简体   繁体   中英

Kafka producer disabling

I have an app that consumes one Kafka topic, doing things, and produces the result into two different topics.

The tricky thing is that the outgoing topic may not exist yet and I need to have an opportunity to switch off the producer on demand by environment varieable.

I can disable send() method this way, but at app startup it tries to connect to the topic to get metadata and spams:

Error while fetching metadata ... UNKNOWN_TOPIC_OR_PARTITION

Tried different producer-properties but with no luck. Also tried to annotate producer class with ConditionalOnProperty, but the bean is required by service class.

By default producers and consumers are started automatically. You can disable it using auto-startup Consumer/Producer properties - https://docs.spring.io/spring-cloud-stream/docs/3.1.5/reference/html/spring-cloud-stream.html#_producer_properties .

You can also start/stop bindings via actuator REST endpoints - https://docs.spring.io/spring-cloud-stream/docs/3.1.5/reference/html/spring-cloud-stream.html#binding_visualization_control

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM