Reputation: 1394
I have a Spring JMS application configured via annotations and I am trying to provide some information to the application BEFORE the JMS listeners start. After that, I want to start manually the listeners.
With the following configuration:
@Bean(name = "queueContainerFactory")
public JmsListenerContainerFactory<?> queue(ConnectionFactory cf) {
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
ActiveMQConnectionFactory amqCf = (ActiveMQConnectionFactory) cf;
factory.setConnectionFactory(amqCf);
...
}
I saw the option: factory.setAutoStartup(FALSE);
With this the application context starts and the @JmsListener
is not started but I do not know how to start the JMS container factory manually.
@JmsListener(containerFactory="queueContainerFactory", destination = "${destination}")
public void jmsListener(String message) {
...
}
Upvotes: 2
Views: 1190
Reputation: 121552
You have to autowire JmsListenerEndpointRegistry
and obtain the particular MessageListenerContainer
by its id
. Where that id
you can configure on the @JmsListener
:
/**
* The unique identifier of the container managing this endpoint.
* <p>If none is specified, an auto-generated one is provided.
* @see org.springframework.jms.config.JmsListenerEndpointRegistry#getListenerContainer(String)
*/
String id() default "";
That might look like:
@JmsListener(id ="myContainer",
containerFactory="queueContainerFactory",
destination = "${destination}")
public void jmsListener(String message) {
...
}
...
@Autowired
JmsListenerEndpointRegistry jmsListenerEndpointRegistry;
...
this.jmsListenerEndpointRegistry.getListenerContainer("myContainer").start();
Upvotes: 1