Skip to content

Commit a95fb49

Browse files
authored
Merge pull request #8 from serdarkocerr/restandmicroservice
run as docker container
2 parents c678afd + 0151955 commit a95fb49

7 files changed

Lines changed: 197 additions & 11 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
version: '3.7'
2+
3+
services:
4+
currency-exchange:
5+
image: serdarkocerr/microservices-currency-exchange-service:0.0.1-SNAPSHOT
6+
mem_limit: 700m
7+
ports:
8+
- "8000:8000"
9+
networks:
10+
- currency-network
11+
depends_on:
12+
- naming-server
13+
- rabbitmq
14+
15+
environment:
16+
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://naming-server:8761/eureka
17+
SPRING.ZIPKIN.BASEURL: http://zipkin-server:9411/
18+
RABBIT_URI: amqp://guest:guest@rabbitmq:5672
19+
SPRING_RABBITMQ_HOST: rabbitmq
20+
SPRING_ZIPKIN_SENDER_TYPE: rabbit
21+
22+
currency-conversion:
23+
image: serdarkocerr/microservices-currency-conversion-service:0.0.1-SNAPSHOT
24+
mem_limit: 700m
25+
ports:
26+
- "8100:8100"
27+
networks:
28+
- currency-network
29+
depends_on:
30+
- naming-server
31+
- rabbitmq
32+
33+
environment:
34+
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://naming-server:8761/eureka
35+
SPRING.ZIPKIN.BASEURL: http://zipkin-server:9411/
36+
RABBIT_URI: amqp://guest:guest@rabbitmq:5672
37+
SPRING_RABBITMQ_HOST: rabbitmq
38+
SPRING_ZIPKIN_SENDER_TYPE: rabbit
39+
40+
api-gateway:
41+
image: serdarkocerr/microservices-api-gateway:0.0.1-SNAPSHOT
42+
mem_limit: 700m
43+
ports:
44+
- "8765:8765"
45+
networks:
46+
- currency-network
47+
depends_on:
48+
- naming-server
49+
- rabbitmq
50+
51+
environment:
52+
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://naming-server:8761/eureka
53+
SPRING.ZIPKIN.BASEURL: http://zipkin-server:9411/
54+
RABBIT_URI: amqp://guest:guest@rabbitmq:5672
55+
SPRING_RABBITMQ_HOST: rabbitmq
56+
SPRING_ZIPKIN_SENDER_TYPE: rabbit
57+
58+
59+
naming-server:
60+
image: serdarkocerr/microservices-naming-server:0.0.1-SNAPSHOT
61+
mem_limit: 700m
62+
ports:
63+
- "8761:8761"
64+
networks:
65+
- currency-network
66+
67+
zipkin-server:
68+
image: openzipkin/zipkin:2.23
69+
mem_limit: 300m
70+
ports:
71+
- "9411:9411"
72+
networks:
73+
- currency-network
74+
depends_on:
75+
- rabbitmq
76+
environment:
77+
RABBIT_URI: amqp://guest:guest@rabbitmq:5672
78+
restart: always #Restart if there is a problem starting up
79+
80+
rabbitmq:
81+
image: rabbitmq:3.8.12-management
82+
mem_limit: 300m
83+
ports:
84+
- "5672:5672"
85+
- "15672:15672"
86+
networks:
87+
- currency-network
88+
89+
networks:
90+
currency-network:
91+

Spring/RestAndMicroservice/microservices/api-gateway/pom.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
34
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
45
<modelVersion>4.0.0</modelVersion>
56
<parent>
67
<groupId>org.springframework.boot</groupId>
78
<artifactId>spring-boot-starter-parent</artifactId>
89
<version>2.6.0-M2</version>
9-
<relativePath/> <!-- lookup parent from repository -->
10+
<relativePath /> <!-- lookup parent from repository -->
1011
</parent>
1112
<groupId>com.serdar.microservices</groupId>
1213
<artifactId>api-gateway</artifactId>
@@ -76,6 +77,12 @@
7677
<plugin>
7778
<groupId>org.springframework.boot</groupId>
7879
<artifactId>spring-boot-maven-plugin</artifactId>
80+
<configuration>
81+
<image>
82+
<name>serdarkocerr/microservices-${project.artifactId}:${project.version}</name>
83+
</image>
84+
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
85+
</configuration>
7986
</plugin>
8087
</plugins>
8188
</build>

Spring/RestAndMicroservice/microservices/currency-conversion-service/pom.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
34
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
45
<modelVersion>4.0.0</modelVersion>
56
<parent>
67
<groupId>org.springframework.boot</groupId>
78
<artifactId>spring-boot-starter-parent</artifactId>
89
<version>2.6.0-M2</version>
9-
<relativePath/> <!-- lookup parent from repository -->
10+
<relativePath /> <!-- lookup parent from repository -->
1011
</parent>
1112
<groupId>com.serdar.microservices</groupId>
1213
<artifactId>currency-conversion-service</artifactId>
@@ -52,13 +53,13 @@
5253
<groupId>org.springframework.cloud</groupId>
5354
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
5455
</dependency>
55-
56-
56+
57+
5758
<dependency>
5859
<groupId>org.springframework.cloud</groupId>
5960
<artifactId>spring-cloud-starter-openfeign</artifactId>
6061
</dependency>
61-
62+
6263
<dependency>
6364
<groupId>org.springframework.boot</groupId>
6465
<artifactId>spring-boot-devtools</artifactId>
@@ -88,6 +89,12 @@
8889
<plugin>
8990
<groupId>org.springframework.boot</groupId>
9091
<artifactId>spring-boot-maven-plugin</artifactId>
92+
<configuration>
93+
<image>
94+
<name>serdarkocerr/microservices-${project.artifactId}:${project.version}</name>
95+
</image>
96+
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
97+
</configuration>
9198
</plugin>
9299
</plugins>
93100
</build>

Spring/RestAndMicroservice/microservices/currency-conversion-service/src/main/resources/application.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ eureka.instance.prefer.ip-address=true
99

1010
#trace every request if 1.0, 0.1--> means trace 10% request
1111
spring.sleuth.sampler.probability=1.0
12-
12+
#spring.zipkin.baseUrl=http://localhost:9411/
13+
#spring.zipkin.sender.type=rabbit # default http

Spring/RestAndMicroservice/microservices/currency-exchange-service/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
<plugin>
107107
<groupId>org.springframework.boot</groupId>
108108
<artifactId>spring-boot-maven-plugin</artifactId>
109+
<configuration>
110+
<image>
111+
<name>serdarkocerr/microservices-${project.artifactId}:${project.version}</name>
112+
</image>
113+
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
114+
</configuration>
109115
</plugin>
110116
</plugins>
111117
</build>

Spring/RestAndMicroservice/microservices/naming-server/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
<plugin>
5757
<groupId>org.springframework.boot</groupId>
5858
<artifactId>spring-boot-maven-plugin</artifactId>
59+
<configuration>
60+
<image>
61+
<name>serdarkocerr/microservices-${project.artifactId}:${project.version}</name>
62+
</image>
63+
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
64+
</configuration>
5965
</plugin>
6066
</plugins>
6167
</build>

Spring/RestAndMicroservice/microservices/notes.txt

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ create microservice:
111111
resilience4j.ratelimiter.instances.default.limitRefreshPeriod=10s
112112

113113
4.
114-
-------------- Zipkin Distrubuted Tracing System ----------------
114+
-------------- Zipkin Distributed Tracing System ----------------
115115

116116
api-gateway -----> Currency Conversion Microservice ----> Currency Exchange Microservice
117117
- - -
@@ -163,11 +163,79 @@ run services and go to http://localhost:9411/zipkin/ , click Run Query
163163
view requests on zipkin UI.
164164

165165
--------------------------
166+
----DOCKER CONTAINER---
167+
This plugin helps to us create image for our container.
168+
IF_NOT_PRESENT--> search image first locally, if not present pull from docker hub
169+
170+
171+
<build>
172+
<plugins>
173+
<plugin>
174+
<groupId>org.springframework.boot</groupId>
175+
<artifactId>spring-boot-maven-plugin</artifactId>
176+
<configuration>
177+
<image>
178+
<name>serdarkocerr/mmv2-${project.artifactId}:${project.version}</name>
179+
</image>
180+
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
181+
</configuration>
182+
</plugin>
183+
</plugins>
184+
</build>
185+
186+
187+
Create image:
188+
Run as -> Maven Build... -> Goal = spring-boot:build-image -DskipTests
189+
190+
docker run -p 8000:8000 serdarkocerr/microservices-currency-exchange-service:0.0.1-SNAPSHOT
191+
test --> http://localhost:8000/currency-exchange/from/USD/to/TRY
192+
193+
Docker compose run multiple services from yaml file. So that create docker-compose.yml file
194+
docker-compose --version
195+
196+
run from yml file
197+
docker-compose up
198+
199+
go to:
200+
-http://localhost:8765/currency-exchange/from/USD/to/TRY
201+
-http://localhost:8100/currency-conversion-feign/from/USD/to/TRY/quantity/10
202+
-http://localhost:8000/currency-exchange/from/USD/to/TRY
203+
-http://localhost:8100/currency-conversion/from/USD/to/TRY/quantity/10 --> will not work.
204+
Because in controller response uri set as localhost. So you can change it
205+
using application.properties variable from docker image.!!
206+
207+
208+
209+
210+
NOTE: eureka url in currency-exchange-server's application.properties saved as
211+
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
212+
but localhost is not same currency-exchange-server container and naming-server container.
213+
so that you have to set as naming-server ip address or set environment in docker-compose.yml
214+
file to register naming-server.
215+
environment:
216+
EUREKA.CLIENT.SERVICEURL.DEFAULTZONE: http://naming-server:8761/eureka
217+
Ayni durum ZIPKIN server icinde gecerlidir.
218+
219+
220+
----------------------
221+
222+
166223
---- With Rabbit MQ ------
167-
What if Zipkin gone or not running? you should your trace in mq like rabbitMQ
168-
224+
What if Zipkin is gone or not running? microservices can put information to mq like rabbitMQ.
225+
226+
Normally zipkin sendr type have to define in application.properties as
227+
'spring.zipkin.sender.type=web' but default is web so that you dont have to define.
169228

229+
If you decide to use rabbit mq, you should set
230+
'spring.zipkin.sender.type=rabbit' or
231+
if you use docker container, you can define environment in yaml as
232+
'SPRING.ZIPKIN.SENDER.TYPE: rabbit
170233

234+
add rabbit mq server in yaml to run RABBIT MQ in docker container.
235+
236+
Also add rabbit mq settings to environment in yaml file.
237+
238+
-----------------------------------------------------------------------
171239

172240

173241

0 commit comments

Comments
 (0)