ewolff / microservice-kafka

Demo to show how Apache Kafka can be used for communication between microservices
Apache License 2.0
584 stars 302 forks source link

Invoice and Shipment services don't start due to missing topic ? #17

Closed jmdev68 closed 4 years ago

jmdev68 commented 4 years ago

tried to run the application and i am able to create / submit an order - however the invoice and shipment services are not running. when checking the docker log files for those services i get the following hint :

2020-07-04 15:22:34.933 INFO 6 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1593876154931 2020-07-04 15:22:35.134 WARN 6 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is java.lang.IllegalStateException: Topic(s) [order] is/are not present and missingTopicsFatal is true 2020-07-04 15:22:35.135 WARN 6 --- [ main] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'tomcatMetricsBinder': java.lang.NullPointerException 2020-07-04 15:22:35.136 INFO 6 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor' 2020-07-04 15:22:35.136 INFO 6 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2020-07-04 15:22:35.137 INFO 6 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2020-07-04 15:22:35.144 INFO 6 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2020-07-04 15:22:35.146 INFO 6 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2020-07-04 15:22:35.157 INFO 6 --- [ main] ConditionEvaluationReportLoggingListener :

ewolff commented 4 years ago

Interesting, thanks for submitting! Kafka itself creates the topics so it should always be there. I guess there is a racing condition when shipping / order contacts the Kafka server and the Kafka server starts up but hasn't yet created the topic. I could reproduce the problem and it should be fixed. Please reopen if it was not fixed. Thanks!

jmdev68 commented 4 years ago

Thanks a lot Eberhard. It DOES work now (I pulled the latest code, rebuild the java code and rebuild the docker images. During the java build process i was a little bit skeptic as the test failed (see below) but building without test and starting via docker compose worked. thanks Jörg

020-07-06 21:38:23.910 WARN 9928 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient : [Consumer clientId=consumer-2, groupId=shipping] Connection to node 0 (localhost/127.0.0.1:35705) could not be established. Broker may not be available. 2020-07-06 21:38:24.238 WARN 9928 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : [Producer clientId=producer-1] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.038 s - in com.ewolff.microservice.shipping.ShippingWebIntegrationTest [INFO] [INFO] Results: [INFO] [ERROR] Failures: [ERROR] ShipmentKafkaTest.orderAreReceived:46 Expected: is a value greater than <1L> but: <1L> was equal to <1L> [INFO] [ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] microservice-kafka ................................. SUCCESS [ 0.539 s] [INFO] microservice-kafka-order ........................... SUCCESS [ 14.576 s] [INFO] microservice-kafka-shipping ........................ FAILURE [01:20 min] [INFO] microservice-kafka-invoicing ....................... SKIPPED

ewolff commented 4 years ago

Thanks. The tests do fail, I believe this is a problem with the ports for the embedded Kafka. On WSL2 on my machine they fail, on Windows Powershell they work. Not sure how to fix that. 😟