PacktPublishing / Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud

Hands-On Microservices with Spring Boot and Spring Cloud, published by Packt
MIT License
464 stars 405 forks source link

Chapter 9 code has runtime errors #1

Closed dwschulze closed 5 years ago

dwschulze commented 5 years ago

I run the Chapter 9 code with docker-compose up like the other chapters. When I use a curl POST command to create a product (as in previous chapters) and then a curl GET to read the product just created I get a 404 error.

Also in Chapter 9 test-em-all.bash doesn't start. It just keeps retrying.

magnus-larsson commented 5 years ago

Thanks for the issue report!

Can you run the following commands and let me know the results:

  1. docker ps
  2. curl http://localhost:8080/actuator/health
dwschulze commented 5 years ago

Edit: Working now (see below). I had to change the curl GET to use product-composite, not product. Also test-em-all.bash is now working too.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c9db0c0a7653 chapter09_recommendation "java -jar /app.jar" 37 seconds ago Up 36 seconds 8080/tcp chapter09_recommendation_1 9ebc4a660ee0 chapter09_product-composite "java -jar /app.jar" 37 seconds ago Up 36 seconds 0.0.0.0:8080->8080/tcp chapter09_product-composite_1 9aadab3f9908 chapter09_product "java -jar /app.jar" 37 seconds ago Up 35 seconds 8080/tcp chapter09_product_1 13318caafb65 chapter09_review "java -jar /app.jar" 37 seconds ago Up 36 seconds 8080/tcp chapter09_review_1 f0f23004da74 mongo:3.6.9 "docker-entrypoint.s…" 49 seconds ago Up 48 seconds (healthy) 0.0.0.0:27017->27017/tcp chapter09_mongodb_1 cf0196aecb8b chapter09_eureka "java -jar /app.jar" 49 seconds ago Up 47 seconds 0.0.0.0:8761->8761/tcp chapter09_eureka_1 cc1f605a7f8e rabbitmq:3.7.8-management "docker-entrypoint.s…" 49 seconds ago Up 48 seconds (healthy) 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp chapter09_rabbitmq_1 10c8d36c8e9f mysql:5.7 "docker-entrypoint.s…" 49 seconds ago Up 48 seconds (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp chapter09_mysql_1 $

$ curl http://localhost:8080/actuator/health {"status":"UP","details":{"hystrix":{"status":"UP"},"binders":{"status":"UP","details":{"rabbit":{"status":"UP","details":{"binderHealthIndicator":{"status":"UP","details":{"version":"3.7.8"}}}}}},"diskSpace":{"status":"UP","details":{"total":1006529605632,"free":585188564992,"threshold":10485760}},"rabbit":{"status":"UP","details":{"version":"3.7.8"}},"refreshScope":{"status":"UP"},"discoveryComposite":{"status":"UP","details":{"discoveryClient":{"status":"UP","details":{"services":["product-composite","product","review","recommendation"]}},"eureka":{"description":"Remote status from Eureka server","status":"UP","details":{"applications":{"PRODUCT-COMPOSITE":1,"PRODUCT":1,"REVIEW":1,"RECOMMENDATION":1}}}}},"coreServices":{"status":"UP","details":{"product":{"status":"UP"},"review":{"status":"UP"},"recommendation":{"status":"UP"}}}}}

dwschulze commented 5 years ago

Here are the tests I tried. The product, review, and recommendation are created, but the GET returns a 404:

$ curl -X POST "http://localhost:8080/product-composite" -H "accept: /" -H "Content-Type: application/json" -d "{ \"name\": \"test\", \"productId\": 3, \"recommendations\": [ { \"author\": \"test\", \"content\": \"test\", \"rate\": 10, \"recommendationId\": 2 } ], \"reviews\": [ { \"author\": \"test\", \"content\": \"test\", \"reviewId\": 2, \"subject\": \"test subject\" } ], \"serviceAddresses\": { \"cmp\": \"string\", \"pro\": \"string\", \"rec\": \"string\", \"rev\": \"string\" }, \"weight\": 0}"

$ docker-compose exec mongodb mongo product-db --quiet --eval "db.products.find()" { "_id" : ObjectId("5d9c8aa108bb3a00019faae1"), "version" : 0, "productId" : 3, "name" : "test", "weight" : 0, "_class" : "se.magnus.microservices.core.product.persistence.ProductEntity" }

$ docker-compose exec mongodb mongo recommendation-db --quiet --eval "db.recommendations.find()" { "_id" : ObjectId("5d9c8aa10ec83c0001022f51"), "version" : 0, "productId" : 3, "recommendationId" : 2, "author" : "test", "rating" : 10, "content" : "test", "_class" : "se.magnus.microservices.core.recommendation.persistence.RecommendationEntity" }

$ docker-compose exec mysql mysql -uuser -ppwd review-db -e "select * from reviews" mysql: [Warning] Using a password on the command line interface can be insecure. +----+--------+---------+------------+-----------+--------------+---------+ | id | author | content | product_id | review_id | subject | version | +----+--------+---------+------------+-----------+--------------+---------+ | 1 | test | test | 3 | 2 | test subject | 0 | +----+--------+---------+------------+-----------+--------------+---------+

$ curl localhost:8080/product/3 {"timestamp":"2019-10-08T13:11:17.262+0000","path":"/product/3","status":404,"error":"Not Found","message":null}

dwschulze commented 5 years ago

Looks like my problem was doing a GET against the product service. I should have done it against product-composite:

$ curl localhost:8080/product-composite/3 {"productId":3,"name":"test","weight":0,"recommendations":[{"recommendationId":2,"author":"test","rate":10,"content":"test"}],"reviews":[{"reviewId":2,"author":"test","subject":"test subject","content":"test"}],"serviceAddresses":{"cmp":"9ebc4a660ee0/172.23.0.8:8080","pro":"9aadab3f9908/172.23.0.7:8080","rev":"13318caafb65/172.23.0.6:8080","rec":"c9db0c0a7653/172.23.0.9:8080"}}

I also tried test-em-all.bash again and it's now working too. Last night it didn't work. Sorry for the false alarm.

magnus-larsson commented 5 years ago

Great! No worries, please file new issues if you run into any problems!