Spring DefaultMessageListenerContainer - 侦听器未读取 Websphere MQ 上的消息
我正在使用 Spring 3.0 - DefaultMessageListenerContainer 连接到 Websphere 6 MQ。 MQ 上已存在一些消息。当我运行测试时,实现 SessionAwareMessageListener 的侦听器将启动。但 onMessage() 不会被调用。所以问题是已经在队列中的消息没有被读取。
根据文档,autoStartup 默认情况下为 true(并且我没有更改此设置)。根据我的理解,启动时,侦听器应该读取队列中的任何现有消息,并且应该调用 onMessage() 。如果这种理解有误,请告诉我。
以下是配置文件中的片段:
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="destinationName">
<value>${queue}</value>
</property>
<property name="messageListener" ref="exampleMessageListener" />
<property name="concurrentConsumers" value="1" />
<property name="maxConcurrentConsumers" value="1" />
<property name="idleTaskExecutionLimit" value="4" />
<property name="maxMessagesPerTask" value="4" />
<property name="receiveTimeout" value="5000" />
<property name="recoveryInterval" value="5000" />
<property name="sessionTransacted" value="true" />
<property name="transactionManager" ref="jmsTransActionManager" />
</bean>
注意:没有错误/异常,测试应用程序启动得很好。
任何解决此问题的指示都会有很大帮助。
谢谢,
RJ
I am using Spring 3.0 - DefaultMessageListenerContainer to connect to a Websphere 6 MQ. There are some messages already present on the MQ. When I run my test, the listener implementing SessionAwareMessageListener is started. But the onMessage() does not get invoked. So the problem is that the messages already in the queue are not read.
As per the docs, autoStartup is true by default (and I have not changed this). As per my underatanding, On startup, the listener should read the Queue for any existing messages and onMessage() should get invoked. Please let me know if this understanding is wrong.
Here is the snippet from the config file:
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="destinationName">
<value>${queue}</value>
</property>
<property name="messageListener" ref="exampleMessageListener" />
<property name="concurrentConsumers" value="1" />
<property name="maxConcurrentConsumers" value="1" />
<property name="idleTaskExecutionLimit" value="4" />
<property name="maxMessagesPerTask" value="4" />
<property name="receiveTimeout" value="5000" />
<property name="recoveryInterval" value="5000" />
<property name="sessionTransacted" value="true" />
<property name="transactionManager" ref="jmsTransActionManager" />
</bean>
Note: There is no error/exception, the test app starts up just fine.
Any pointers to resolve this will be of great help.
Thanks,
RJ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题已解决。测试类在侦听器获取消息之后但在将消息显示为输出之前终止。因此,第一条消息(最高优先级的消息)从队列中丢失了。
后来,由于我添加了事务管理器,侦听器将消息放回到队列中(显示警告为由于侦听器容器已停止而拒绝接收到的消息)。由于这是一个警告,并且我的记录器处于调试级别,因此我之前错过了这一点。
将 thread.sleep 放入测试类中可确保它运行更长时间,并且侦听器可以按优先级顺序读取队列中的所有消息:)
干杯,
RJ
The issue is resolved. The test class was terminating after the listener got hold of the message but before it could show the message as output. So the first message (highest priority one) was getting lost from the queue.
Later as I had included a Transaction Manager, the listener was putting the message back on the queue (showing a warning as Rejecting received message because of the listener container having been stopped in the meantime). As this was a warning and my logger was at a Debug level, I missed this earlier.
Putting a thread.sleep in the test class made sure that it is running for a longer time and the listener could read all the messages in the queue in the order of priority :)
cheers,
RJ