Configuration which allows to disable cloud stream?
Asked Answered
E

2

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?

Eardrop answered 12/5, 2020 at 5:26 Comment(0)
P
9

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.

Prodigal answered 14/12, 2021 at 23:23 Comment(1)
I have searched far and wide for this answer, and this is exactly what I needed. Thanks!Fermanagh
M
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.

Manganese answered 12/5, 2020 at 13:4 Comment(4)
but this still starts AdminClientConfig and tries to connect to kafka. I want this entire setup to be disabledEardrop
Use spring.cloud.stream.kafka.binder.autoCreateTopics=false to stop that.Manganese
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: falseEardrop
Oh, right; yes I see - I suggest you ask for a new feature against the binder.Manganese

© 2022 - 2025 — McMap. All rights reserved.