0

Is it possible to bind many queues to exactly one event handler ? The key thing is that these queues will be added (binded) dynamically, first one, next two and so on. I would like to have only one event handler.

Maybe code-based created queue which is backed by n other existing queues ?

1 Answers1

0

If you use Spring AMPQ, then you should be familiar with the ListenerContainer abstraction. So, you configure your single listener (handler in your terms) and let the container to manage queues and other connection and lifecycle options.

You can find all the required options in the Reference Manual. Also see Listener Container Queues:

See methods addQueues, addQueueNames, removeQueues and removeQueueNames

More info in the: Dynamically add new queues, bindings and exchanges as beans

Community
  • 1
  • 1
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • One thing is unclear: You suggest `addQueues`, however later you give link in which we manually modify spring's context: `context.getBeanFactory().registerSingleton("foo", new Queue("foo"));` What's go on ? –  Mar 21 '17 at 21:26
  • 1
    Nothing. Just a complement. This story is about how to modify container. That one how to add queues for management in the application context. – Artem Bilan Mar 21 '17 at 21:28
  • So I can use one of them ? –  Mar 21 '17 at 21:28
  • No, for your use-case you have to use my answer. If you need administration of new queues, you have to register them as beans. The container works pretty well just with queue names. – Artem Bilan Mar 21 '17 at 21:30
  • Ok, so I must register queues as beans. `context.getBeanFactory().registerSingleton("foo", new Queue("foo"))` and then call `addQueues`? Keep in mind that I use spring-boot. –  Mar 23 '17 at 15:24
  • 1
    The Spring Boot subject unrelated. If you have queues on the Broker already, you need only their names to subscribe at runtime. Otherwise yes, you have to register them as beans first of all and call `admin.initialize()`. – Artem Bilan Mar 23 '17 at 15:31
  • I have always queues on broker created. I only would like to subscribe queues (dynamically, at runtime). Listener is written also. –  Mar 23 '17 at 15:32
  • So, you don't need that `registerSingleton()` hack. You only need `addQueueNames()`. That's it – Artem Bilan Mar 23 '17 at 15:44
  • I need `SimpleMessageListenerContainer` to call `addQueueNames`. I can do it configure bean manually. However, there is no bean automatically created that I may inject with `@Autowired` ? –  Mar 24 '17 at 07:11