0

I have a usecase where i want to create topic and its consumer on demand i.e, when i host a product-1 for sale it should create a topic and consumer for product-1 and if i create product-2 it should create a topic and consumer for product-2.

enter image description here

creation of topic and consumer should be on-demand so that the traffic on one product should not affect other.

Im able to create new topic on demand and push new task to that topic and able to read it from same consumer which i have configured to read from dynamic topics using pattern, but stuck at creating consumer dedicated for that new topic on the go

can anyone please help me on how to create consumers on the go subscribing to a topic?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Code Wizard
  • 46
  • 2
  • 7
  • Where exactly are you stuck with this? – OneCricketeer Jul 10 '23 at 12:31
  • @OneCricketeer im able to create new topic on demand and push new task to that topic and able to read it from same consumer which i have configured to read from dynamic topics using pattern, but stuck at creating consumer dedicated for that new topic on the go. – Code Wizard Jul 11 '23 at 03:36
  • You can create `new KafkaConsumer()` and `subscribe("new-topic")` – OneCricketeer Jul 11 '23 at 19:36

1 Answers1

0

Given that you originally tagged this question with (@OneCricketeer removed the tag; I added it back), see this answer and its comments for links to a bunch of answers showing several techniques for adding consumers dynamically, using Spring.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179