book-microservices-v2 / chapter08d Goto Github PK
View Code? Open in Web Editor NEWLearn Microservices with Spring Boot (2nd edition) - Chapter 8 (FINAL)
Home Page: https://tpd.io/book-extra
Learn Microservices with Spring Boot (2nd edition) - Chapter 8 (FINAL)
Home Page: https://tpd.io/book-extra
Hi Moisés Garcia,
How are you? I hope you are doing fine.
First of all, congratulations for this great book. You touch in all most every challenge that we face when adopting a microservice architecture. And you do it on a very pragmatic way. Your language is simple and easy to follow. At the same time you introduce several nice tools. A big thank you for writing this book to us.
I am almost finishing the book. I am no chapter 8 on Docker Compose sub chapter but I am with difficulties to bring up all application. Via docker composer i was able to bring up successfully Consul, Rabbitmq, frontend and gateway. multiplication and gamification are throwing exceptions because they cannot connect to Rabbitmq
Status of containers
root@mpssantos-Lenovo-Yoga-S740-14IIL:/home/mpssantos/Development/workspace/springbootmicroservices/docker-config# docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
consul docker-entrypoint.sh agent ... Up 8300/tcp, 8301/tcp, 8301/udp, 8302/tcp, 8302/udp, 0.0.0.0:8500->8500/tcp,:::8500->8500/tcp, 8600/tcp, 0.0.0.0:8600->8600/udp,:::8600->8600/udp
docker-config_consul-importer_1 /bin/sh -c until consul kv ... Exit 0
docker-config_frontend_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:3000->80/tcp,:::3000->80/tcp
docker-config_gamification_1 java -jar gamification-0.0 ... Up 8081/tcp
docker-config_gateway_1 /cnb/process/web Up 0.0.0.0:8000->8000/tcp,:::8000->8000/tcp
docker-config_multiplication_1 /cnb/process/web Up
rabbitmq docker-entrypoint.sh rabbi ... Up 15671/tcp, 0.0.0.0:15672->15672/tcp,:::15672->15672/tcp, 15691/tcp, 15692/tcp, 25672/tcp, 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp,:::5672->5672/tcp
Docker Compose
version: "3"
services:
frontend:
image: challenges-frontend:1.0
ports:
- '3000:80'
multiplication:
image: multiplication:0.0.1-SNAPSHOT
environment:
- SPRING_PROFILES_ACTIVE=docker
- SPRING_CLOUD_CONSUL_HOST=consul
depends_on:
- rabbitmq-dev
- consul-importer
networks:
- microservices
gamification:
image: gamification:0.0.1
environment:
- SPRING_PROFILES_ACTIVE=docker
- SPRING_CLOUD_CONSUL_HOST=consul
depends_on:
- rabbitmq-dev
- consul-importer
networks:
- microservices
gateway:
image: gateway:0.0.1-SNAPSHOT
ports:
- '8000:8000'
environment:
- SPRING_PROFILES_ACTIVE=docker
- SPRING_CLOUD_CONSUL_HOST=consul
depends_on:
- rabbitmq-dev
- consul-importer
networks:
- microservices
consul-importer:
image: consul-importer:1.0
depends_on:
- consul-dev
networks:
- microservices
consul-dev:
image: consul:1.7.2
container_name: consul
ports:
- '8500:8500'
- '8600:8600/udp'
command: 'agent -dev -node=learnmicro -client=0.0.0.0 -log-level=INFO'
networks:
- microservices
rabbitmq-dev:
image: rabbitmq:3-management
container_name: rabbitmq
ports:
- '5672:5672'
- '15672:15672'
networks:
- microservices
networks:
microservices:
driver: bridge
consul-kv-docker.json
[
{
"key": "config/",
"flags": 0,
"value": ""
},
{
"key": "config/defaults,docker/",
"flags": 0,
"value": ""
},
{
"key": "config/defaults,docker/application.yml",
"flags": 0,
"value": "c3ByaW5nOgogIHJhYmJpdG1xOgogICAgaG9zdDogcmFiYml0bXEKICBjbG91ZDoKICAgIGNvbnN1bDoKICAgICAgZGlzY292ZXJ5OgogICAgICAgIGluc3RhbmNlLWlkOiAke3NwcmluZy5hcHBsaWNhdGlvbi5uYW1lfS0ke3JhbmRvbS5pbnQoMTAwMCl9"
}
]
Exception
022-01-28 23:52:06.396 INFO 1 --- [nio-8080-exec-5] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
multiplication_1 | 2022-01-28 23:52:06.397 WARN 1 --- [nio-8080-exec-5] o.s.b.a.amqp.RabbitHealthIndicator : Rabbit health check failed
multiplication_1 |
multiplication_1 | org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
multiplication_1 | at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:602) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:724) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:252) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2165) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2138) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2118) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.boot.actuate.amqp.RabbitHealthIndicator.getVersion(RabbitHealthIndicator.java:49) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.amqp.RabbitHealthIndicator.doHealthCheck(RabbitHealthIndicator.java:44) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthIndicator.getHealth(HealthIndicator.java:37) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointWebExtension.getHealth(HealthEndpointWebExtension.java:87) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointWebExtension.getHealth(HealthEndpointWebExtension.java:45) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:130) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointSupport.getAggregateContribution(HealthEndpointSupport.java:141) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:126) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:95) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:66) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointWebExtension.health(HealthEndpointWebExtension.java:73) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
multiplication_1 | at org.springframework.boot.actuate.health.HealthEndpointWebExtension.health(HealthEndpointWebExtension.java:62) ~[spring-boot-actuator-2.6.2.jar:2.6.2]
MORE STACK STRACE
multiplication_1 | Caused by: java.net.ConnectException: Connection refused
multiplication_1 | at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
multiplication_1 | at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source) ~[na:na]
multiplication_1 | at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source) ~[na:na]
multiplication_1 | at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source) ~[na:na]
multiplication_1 | at java.base/java.net.SocksSocketImpl.connect(Unknown Source) ~[na:na]
multiplication_1 | at java.base/java.net.Socket.connect(Unknown Source) ~[na:na]
multiplication_1 | at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.13.1.jar:5.13.1]
multiplication_1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1223) ~[amqp-client-5.13.1.jar:5.13.1]
multiplication_1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1173) ~[amqp-client-5.13.1.jar:5.13.1]
multiplication_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:640) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:615) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:565) ~[spring-rabbit-2.4.1.jar:2.4.1]
multiplication_1 | ... 79 common frames omitted
multiplication_1 |
consul | 2022-01-28T23:52:06.403Z [WARN] agent: Check is now critical: check=service:multiplication-8080
The gamification exceptions are identical
Looks like the auto configuration for Rabbitmq fails, but i cannot understand why.
Can you spot anything strange? How can i debug? Do you need me to supply any other file config file.
Thank you so much for your help.
Once again congratulation for your book. 5*
I did the final docker-compose.yml file and when I start it I got the following error
Here is my docker-file:
https://github.com/andreykirson/docker_mental_arithmetic
Perhaps it needs to change the settings somewhere else?
logs_1 |
logs_1 | . ____ _ __ _ _
logs_1 | /\ / ' __ _ () __ __ _ \ \ \
logs_1 | ( ( )__ | '_ | '| | ' / ` | \ \ \
logs_1 | \/ )| |)| | | | | || (| | ) ) ) )
logs_1 | ' || .__|| ||| |_, | / / / /
logs_1 | =========||==============|/=////
logs_1 | :: Spring Boot :: (v2.5.4)
logs_1 |
logs_1 | [ ] [,] INFO HV000001: Hibernate Validator 6.2.0.Final
logs_1 | [ ] [,] INFO Starting LogCenralizationApplication v0.0.1-SNAPSHOT using Java 16.0.2 on 0b35fc6a05c3 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
logs_1 | [ ] [,] INFO The following profiles are active: docker
logs_1 | [ ] [,] INFO BeanFactory id=688ff25e-fb79-3dc8-af85-a379b9ede61f
logs_1 | [ ] [,] INFO Bean 'org.springframework.retry.annotation.RetryConfiguration' of type [org.springframework.retry.annotation.RetryConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
logs_1 | [ ] [,] INFO Tomcat initialized with port(s): 8580 (http)
logs_1 | [ ] [,] INFO Initializing ProtocolHandler ["http-nio-8580"]
logs_1 | [ ] [,] INFO Starting service [Tomcat]
logs_1 | [ ] [,] INFO Starting Servlet engine: [Apache Tomcat/9.0.52]
logs_1 | [ ] [,] INFO Initializing Spring embedded WebApplicationContext
logs_1 | [ ] [,] INFO Root WebApplicationContext: initialization completed in 3024 ms
logs_1 | [ ] [,] INFO Exposing 1 endpoint(s) beneath base path '/actuator'
logs_1 | [ ] [,] INFO Starting ProtocolHandler ["http-nio-8580"]
logs_1 | [ ] [,] INFO Tomcat started on port(s): 8580 (http) with context path ''
logs_1 | [ ] [,] INFO Attempting to connect to: [localhost:5672]
logs_1 | [ ] [,] INFO Broker not available; cannot force queue declarations during start: java.net.ConnectException: Connection refused
logs_1 | [ ] [,] INFO Attempting to connect to: [localhost:5672]
logs_1 | [ ] [,] ERROR Failed to check/redeclare auto-delete queue(s).
logs_1 | org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
logs_1 | at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61)
logs_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:602)
logs_1 | at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:724)
logs_1 | at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:252)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2163)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2136)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2116)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueInfo(RabbitAdmin.java:407)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:391)
logs_1 | at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.attemptDeclarations(AbstractMessageListenerContainer.java:1914)
logs_1 | at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1895)
logs_1 | at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1347)
logs_1 | at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1193)
logs_1 | at java.base/java.lang.Thread.run(Unknown Source)
logs_1 | Caused by: java.net.ConnectException: Connection refused
logs_1 | at java.base/sun.nio.ch.Net.pollConnect(Native Method)
logs_1 | at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)
logs_1 | at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source)
logs_1 | at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source)
logs_1 | at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
logs_1 | at java.base/java.net.Socket.connect(Unknown Source)
logs_1 | at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60)
logs_1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1220)
logs_1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1170)
logs_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:640)
logs_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:615)
logs_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:565)
logs_1 | ... 12 common frames omitted
logs_1 | [ ] [,] INFO Attempting to connect to: [localhost:5672]
logs_1 | [ ] [,] INFO Started LogCenralizationApplication in 40.558 seconds (JVM running for 41.286)
logs_1 | [ ] [,] WARN Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
logs_1 | [ ] [,] INFO Restarting Consumer@22368ddc: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
logs_1 | [ ] [,] INFO Attempting to connect to: [localhost:5672]
logs_1 | [ ] [,] ERROR Failed to check/redeclare auto-delete queue(s).
logs_1 | org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
logs_1 | at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61)
logs_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:602)
logs_1 | at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:724)
logs_1 | at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:252)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2163)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2136)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2116)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueInfo(RabbitAdmin.java:407)
logs_1 | at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:391)
logs_1 | at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.attemptDeclarations(AbstractMessageListenerContainer.java:1914)
logs_1 | at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1895)
logs_1 | at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1347)
logs_1 | at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1193)
logs_1 | at java.base/java.lang.Thread.run(Unknown Source)
logs_1 | Caused by: java.net.ConnectException: Connection refused
logs_1 | at java.base/sun.nio.ch.Net.pollConnect(Native Method)
logs_1 | at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)
logs_1 | at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source)
logs_1 | at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source)
logs_1 | at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
logs_1 | at java.base/java.net.Socket.connect(Unknown Source)
logs_1 | at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60)
logs_1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1220)
logs_1 | at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1170)
logs_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:640)
logs_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:615)
logs_1 | at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:565)
I used Docker-Compose bring up the system. but when I play with the browser and find it does not work.
the whole system is running in one server, say: 10.10.10.10; my browser is runing in my laptop, say 10.10.10.11
the browser cannot get any response from multiplication or gamification service, only can connect to challenge-frontend.
I use Chrome Developer Tool, found the request sent from the frontend is "http://localhost:8000/challenges/random". I am wondering if this localhost can work. I guess this local host still referring to my laptop, not the server running the application.
I am not sure if my understanding is correct or not.
Hi, I've tried in cmd to run docker-compose up but received a note : yaml: line 11: did not find expected key
line 11 is command: 'agent -dev -node=learnmicro -client=0.0.0.0 -log-level=INFO'
version: "3"
services:
consul-dev:
image: consul:1.7.2
container_name: consul
ports:
networks:
microservices:
driver: bridge
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.