Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring multiple DefaultJmslistenercontainerfactory

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..

like image 622
user3534483 Avatar asked Oct 23 '25 04:10

user3534483


1 Answers

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.

like image 103
Gary Russell Avatar answered Oct 25 '25 19:10

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!