1

I have created a spring boot application to publish the message to the Kafka queue. For that, I am using spring cloud stream and Kafka binder as dependencies. Problem is my application is continuously trying to connect to Kafka broker if it is down for 2 minutes because of the default configuration. I have reduced that time using the below property and set it to 1000 ms and getting the timeout exception spring.kafka.properties.request.timeout.ms:1000. But still, my spring application is running after the exception. I want it to fail if Kafka broker is not available to connect to. I have tried one more property for that spring.kafka.admin.fail-fast=true but still, the application is running. I have also tried to search for some properties of spring cloud stream and Kafka binder that I can set to fail my application if Kafka broker is not available but couldn't find anything related to that. Please, help me with this.

Please see below for the log of exception.

Caused by: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
        at org.apache.kafka.common.internals.KafkaFutureImpl.wrapAndThrow(KafkaFutureImpl.java:45)
        at org.apache.kafka.common.internals.KafkaFutureImpl.access$000(KafkaFutureImpl.java:32)
        at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:104)
        at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:274)
        at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopicAndPartitions(KafkaTopicProvisioner.java:351)
        at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopicIfNecessary(KafkaTopicProvisioner.java:325)
        at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopic(KafkaTopicProvisioner.java:302)
        ... 33 common frames omitted
Caused by: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Successfully started bean 'outputBindingLifecycle'
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 2147482647
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.binding.BindableProxyFactory - Binding inputs for :interface kafka.stream.RXXXStreams
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Successfully started bean 'inputBindingLifecycle'
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 2147483547
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Successfully started bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'
2019-05-22 06:06:25 [main] DEBUG o.s.b.a.l.ConditionEvaluationReportLoggingListener -
Akshaya KAushik
  • 31
  • 1
  • 12
  • At application startup time, if kafka queue is not available, then it won't start up at all. But if app is already started and after sometime if queue is down, it does not kill the application. Even if you bundle the application as jar, it internally uses embedded tomcat, which runs as a webapp not as a stand alone program – Naveen May 22 '19 at 03:35
  • In my case, the Kafka queue is down before the application starts that is how I am testing the above scenario. – Akshaya KAushik May 22 '19 at 03:38
  • okay in that case, application should not startup. is it possible to share the code that you have used to connect kafka queue? – Naveen May 22 '19 at 03:41
  • I am using spring cloud stream properties for that. PSB for same `spring.cloud.stream.kafka.binder.brokers=${kafkaBrokers} spring.cloud.stream.bindings.output.destination=${kafkaTopicName}` – Akshaya KAushik May 22 '19 at 03:44

1 Answers1

0

Do you have spring-boot-web libraries as dependency? If that's the case, your application will not exit. A full log will be also very helpful.

Edward Aung
  • 3,014
  • 1
  • 12
  • 15
  • yes, I have I am using web dependencies for micrometer. But, when there is a general exception like spring's bean initialization exception in that case my application successfully ends in spite of I am using spring web dependencies. – Akshaya KAushik May 22 '19 at 03:35
  • If I were you, I will set the properties to disable web-nature of the spring boot application. Try referring to https://stackoverflow.com/questions/37187519/about-spring-boot-how-to-disable-web-environment-correctly/37225120 – Edward Aung May 22 '19 at 04:10
  • I am using property `spring.main.web-application-type=none` to disable web-nature but still no progress . – Akshaya KAushik May 22 '19 at 07:19