I am using Spring Cloud Stream and want to programmatically create and bind channels. My use case is that during application startup I receive the dynamic list of Kafka topics to subscribe to. How can I then create a channel for each topic?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Dependency injection into Logback Appenders with S
- Deserialize duplicate keys to list using Jackson
- Serializing a serialized Thrift struct to Kafka in
- How can I access the repository from the entity in
相关文章
- How to load @Configuration classes from separate J
- Using Spring Dynamic Languages Support from Groovy
- Spring JMS : Set ErrorHandler for @JmsListener ann
- ModelMapper: Choose mapping based on Child class
- Configure Spring for CORS
- Remove transitive classpath dependency in gradle
- SpringBoot When file upload size limit exceeds get
- Can we add a feature module to an Angular app afte
I ran into similar scenario recently and below is my sample of creating SubscriberChannels dynamically.
I had a task where I did not know the topics in advance. I solved it by having one input channel which listens to all the topics I need.
https://docs.spring.io/spring-cloud-stream/docs/Brooklyn.RELEASE/reference/html/_configuration_options.html
So my configuration
Then I defined one consumer which handles messages from all these topics.
Note, in your case it may not be a solution. I needed to forward messages to webhooks, so I could have configuration mapping.
I also thought about other ideas. 1) You kafka client consumer without Spring Cloud.
2) Create a predefined number of inputs, for example 50.
And then have a configuration for some of these inputs.
Related discussions
We use Spring Cloud 2.1.1 RELEASE
For the incoming messages, you can explicitly use
BinderAwareChannelResolver
to dynamically resolve the destination. You can check this example whererouter
sink uses binder aware channel resolver.I had to do something similar for the Camel Spring Cloud Stream component. Perhaps the Consumer code to bind a destination "really just a
String
indicating the channel name" would be useful to you?In my case I only bind a single destination, however I don't imagine it being much different conceptually for multiple destinations.
Below is the gist of it:
See here for the full source for more context.