简体   繁体   English

如何手动启动Spring JMS侦听器容器

[英]How to start Spring JMS listener container manually

I have a server side application that consumes message from an JMS queue. 我有一个服务器端应用程序,它消耗来自JMS队列的消息。 I use Spring listener container like this: 我这样使用Spring侦听器容器:

<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. 这样的一个问题是,侦听器一建立便立即开始使用JMS消息。 However, some of the beans the listenerBean depends take some time to initialize (It needs to populate some data from database). 但是, listenerBean依赖的某些bean需要一些时间来初始化(它需要从数据库中填充一些数据)。

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. 因此,如果服务启动时队列中有一些待处理的JMS消息,它将尝试在填充数据完成之前为它提供服务。 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? 我的问题是,如何才能等到数据完全填充后才能自动启动侦听器,以便可以调用start()方法手动启动它?

You can set the autoStartup property on DMLC to keep it from starting until you choose to call start() . 您可以在DMLC上设置autoStartup属性,以防止启动它直到您选择调用start()为止。

Another way is to make sure the connection factory is not created before your other dependent beans are ready. 另一种方法是确保在准备其他依赖Bean之前未创建连接工厂。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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