5

I have a spring boot application which has two functionalities Http requests and kafka Messages handling. I want this application to run in mode which is enabled from application.yml i.e if the user wants to enable it only for http requests then kafka should not be connected.

I could achieve this using normal spring boot kafka plugin by disabling auto configure using the following property at @KafkaListener,

autoStartup="${module.put:false}"

Now we are trying to move to cloud stream and the only way I found to disable it by removing the libraries of cloud stream and binder. Is there any better way to disable it using properties with auto config mode or is there any manual config option available?

Nischal Revooru
  • 195
  • 2
  • 10

2 Answers2

7

I found I could disable the attempt by AdminClient to connect to (down) brokers through the use of a "build" spring profile, then in application-build.yml, exclude the relevant configurations:

spring:
  autoconfigure:
    exclude:
      - org.springframework.cloud.stream.config.BindingServiceConfiguration
      - org.springframework.cloud.stream.function.FunctionConfiguration

This is tested on Spring Cloud Stream 3.1.3.

awgtek
  • 1,483
  • 16
  • 28
0

The Spring Cloud Stream bindings also have autoStartup properties.

https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/3.0.4.RELEASE/reference/html/spring-cloud-stream.html#_consumer_properties

autoStartup

Signals if this consumer needs to be started automatically

Default: true.

Community
  • 1
  • 1
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • 1
    but this still starts AdminClientConfig and tries to connect to kafka. I want this entire setup to be disabled – Nischal Revooru May 12 '20 at 14:12
  • Use `spring.cloud.stream.kafka.binder.autoCreateTopics=false` to stop that. – Gary Russell May 12 '20 at 14:16
  • it still tries to connect even after adding this property.. my config is here spring: cloud: stream: kafka: binder: brokers: localhost:9092 autoCreateTopics: false bindings: input: binder: kafka destination: Test content-type: text/plain group: EXTERNAL consumer: autoStartup: false – Nischal Revooru May 12 '20 at 14:39
  • Oh, right; yes I see - I suggest you ask for a new feature against [the binder](https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/issues). – Gary Russell May 12 '20 at 14:53