0

I have a Spring App working with JMS (ActiveMQ)

I have the following:

@Bean
public DefaultJmsListenerContainerFactory jmsListenerQueueContainerFactoryForSection01(ConnectionFactory selectedConnectionFactory) {
        DefaultJmsListenerContainerFactory djlcf = new DefaultJmsListenerContainerFactory();
        djlcf.setClientId("jmsListenerQueueContainerFactoryForSection01");
        djlcf.setConnectionFactory(selectedConnectionFactory);
        djlcf.setPubSubDomain(false);
        djlcf.setConcurrency("1");
        djlcf.setAutoStartup(true);
        djlcf.setSubscriptionDurable(false);
        return djlcf;
}

And about @JmsListener I have:

@JmsListener(destination="springintegration.queue.local.to.section01", 
       containerFactory="jmsListenerQueueContainerFactoryForSection01")
public void receiveToSection01(Message message){
        logger.info("receiveToSection01: {}", message.toString());
}

I can confirm in ActiveMQ web console that exists in Active Subscribers the jmsListenerQueueContainerFactoryForSection01

Until here I am fine.

Now if I use the @JmsListener's id attribute such as:

@JmsListener(destination="springintegration.queue.local.to.section01",  
             id="abc", 
          containerFactory="jmsListenerQueueContainerFactoryForSection01")
public void receiveToSection01(Message message){
    logger.info("receiveToSection01: {}", message.toString());
}

I never can see the id abc in the ActiveMQ web console. I always see jmsListenerQueueContainerFactoryForSection01

  • I know that @JmsListener concurrency attribute can override the DefaultJmsListenerContainerFactory setConcurrency method

But it does not apply to the id attribute.

According with the @JmsListener'id api says

The unique identifier of the container managing this endpoint. If none is specified, an auto-generated one is provided.

Therefore

  1. When is useful use the @JmsListener id attribute?
  2. Where I can see the @JmsListener id (abc in this case - or even the auto-generated according with the API)
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158

1 Answers1

1

The ID attribute is used to manage the container - the JmsListenerEndpointRegistry bean has methods:

getListenerContainerIds() getListenerContainer(String id)

This allows you to stop/start the containers individually - the containers themselves are not registered as beans in the context so you can't get references to them that way.

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