简体   繁体   中英

How to start Spring JMS listener container manually

I have a server side application that consumes message from an JMS queue. I use Spring listener container like this:

<jms:listener-container connection-factory="myConnectionFactory"
                        ..........
                        concurrency="4-8">
    <jms:listener id="myListener" destination="my.ems.queue" ref="listenerBean" method="method"/>
</jms:listener-container>

This works fine.

One problem of this is that the listener starts to consume JMS message as soon as it is setup. However, some of the beans the listenerBean depends take some time to initialize (It needs to populate some data from database).

Therefore, if the service starts up with some pending JMS message in the queue, it will try to serve it before data is populated completed. This causes some error.

My question is that how can I not start listener automatically until a later stage when data is fully populated, so that I can call the start() method to manually start it?

You can set the autoStartup property on DMLC to keep it from starting until you choose to call start() .

Another way is to make sure the connection factory is not created before your other dependent beans are ready.

<bean class="..." name="myConnectionFactory" depends-on="importantOtherBean"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM