3

In my app, I have 2 diff mq conn factory beans. For this I have 2 diff DefaultJmslistenercontainerfactory beans ex cf1 n cf2. Each of DefaultJmslistenercontainerfactory bean is being referred in seperate @JmsListener. ..Now i want to start stop each listrner programatically , for that I am overriding configureMessageListeners(JmsListenerRegistrar) method where I can set the DefaultJmslistenercontainerfactory instance. Note I only one instance can be set.. then in my code I get spring instance of JmsListenerRegistry from which I can get list dmlc..which I can start n stop However. .since I have set only one DefaultJmslistenercontainerfactory instance, my code returns only one dmlc.. Question here is how can I pass multiple DefaultJmslistenercontainerfactory instances in configureJmsListener() method?? Note- I do not create dmlc manually..I just configure factory..

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
user3534483
  • 2,133
  • 5
  • 22
  • 19

1 Answers1

7

Why are you using configureMessageListeners() ? That is for programmatic endpoint registration, not influencing the configuration of @JmsListener.

Show your configuration (edit the question, don't try to post code/config in comments).

This works fine for me...

@Bean
public JmsListenerContainerFactory<DefaultMessageListenerContainer> one(
        @Qualifier("jmsConnectionFactory1") ConnectionFactory cf) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(cf);
    return factory;
}

@Bean
public JmsListenerContainerFactory<DefaultMessageListenerContainer> two(
        @Qualifier("jmsConnectionFactory2") ConnectionFactory cf) {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(cf);
    return factory;
}

@JmsListener(id="fooListener", destination="foo", containerFactory="one")
public void listen1(String payload) {
    System.out.println(payload + "foo");
}

@JmsListener(id="barListener", destination="bar", containerFactory="two")
public void listen2(String payload) {
    System.out.println(payload + "bar");
}

...

@Autowired
JmsListenerEndpointRegistry registry;

...

MessageListenerContainer fooContainer = registry.getListenerContainer("fooListener");
MessageListenerContainer barContainer = registry.getListenerContainer("barListener");

You can also use registry.getListenerContainers() to get a collection.

I thought I explained all this in my answer to your other question.

Community
  • 1
  • 1
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Yep, got your answer. I thought it will create multiple Registries for different DefaultJmsListenerContainerFactory instances. Is there any way i can get the id's of the Listeners dynamically? I want to display on the screen the id of the listener and its running status. MessageListenerContainer doesn't provide that api – user3534483 Nov 02 '15 at 04:40
  • There's not currently an API to get the list of listener container ids. I have opened a [JIRA Issue](https://jira.spring.io/browse/SPR-13633) which you can track. – Gary Russell Nov 02 '15 at 14:12
  • See [this answer](http://stackoverflow.com/questions/33475344/displaying-the-listeners-and-their-status-in-my-application/33479606#33479606) the functionality should be available shortly. – Gary Russell Nov 02 '15 at 15:51