Reputation: 33
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.
Upvotes: 0
Views: 1640
Reputation: 6106
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
Upvotes: 1