Question

Is there a way to initialise a SimpleMessageListenerContainer as stopped?

i.e. I don't want to consume any JMS messages until later when a user will execute an action to start the JMS container

I've tried calling .stop() as soon as I create the bean... but it seems to be too early.

Calling stop/start later works fine but I don't want to risk processing any messages until the user is ready.

Was it helpful?

Solution

The SimpleMessageListenerContainer implements the SmartLifecycle interface. This interface defines a method isAutoStartup. When this method returns true the component will automatically start.

Most beans implementing the SmartLifecycle interface also have a method setAutoStartup to allow for setting of this property. Setting it to false will disable auto start of the component.

<bean class="org.springframework.jms.listener.SimpleMessageListenerContainer">
    <property name="autoStartup" value="false" />
    // Other Properties initialization
</bean>

Or in Java Config

@Bean
public SimpleMessageListenerContainer container() {
    SimpleMessageListenerContainer smlc = new SimpleMessageListenerContainer();
    smlc.setAutoStartup(false);
    ...
    return smlc;
}

At the moment it isn't possible to set this property using the jms namespace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top