如何在Spring Xml中指定自定义JMS消息侦听器 [英] How to specify custom JMS Message Listener in Spring Xml
问题描述
我是JMS的新手,并且要求将请求批量处理以供侦听器处理.链接: http://sleeplessinslc.blogspot.in/2010/04/batchmessagelistenercontainer-using .html 提供了一个很好的解决方案.我被困在执行相同的.我改写了容器类以使用此新类,而不是使用默认容器:
I am new to JMS and had a requirement to batch requests for a listener to handle. Link: http://sleeplessinslc.blogspot.in/2010/04/batchmessagelistenercontainer-using.html gives a good solution. I am stuck in implementing the same. Instead of using the default container, I overwrote the container-class to use this new class:
<jms:listener-container container-class="org.bsnyder.spring.jms.listener.BatchMessageListenerContainer"
acknowledge="transacted">
<jms:listener destination="CHANDRA.BATCHTEST" ref="messageListener" />
</jms:listener-container>
<bean id="messageListener" class="org.bsnyder.spring.jms.listener.BatchMessageListener" />
此处,BatchMessageListener扩展了Blog中提到的SessionAwareBatchMessageListener.
Here the BatchMessageListener is extending SessionAwareBatchMessageListener as mentioned in the blog.
我得到的错误是:
[ERROR] PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'messageListener' threw exception;
nested exception is java.lang.IllegalArgumentException: Message listener needs to be of type [org.bsnyder.spring.jms.listener.SessionAwareBatchMessageListener]:
Failed properties: Property 'messageListener' threw exception; nested exception is java.lang.IllegalArgumentException: Message listener needs to be of type [org.bsnyder.spring.jms.listener.SessionAwareBatchMessageListener]
我应该更改容器类型(默认情况下为默认")吗? http://docs.spring.io /spring/docs/3.1.x/spring-framework-reference/html/jms.html 不包含有关设置方法的详细信息.
Should I change the container-type (which is "default" by default)? http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/jms.html doesn't contain details on how to set this.
推荐答案
为什么需要从队列中批量读取消息?在这种情况下,我强烈建议您使用spring批处理而不是编写自定义批处理侦听器. Spring批处理很容易配置.
Why do you need to read messages in batch from a queue? In such a case I strongly recommend you to use spring batch instead of writing a custom batch listener. Spring batch is easily configurable.
这篇关于如何在Spring Xml中指定自定义JMS消息侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!