因此,我有一些样板代码可以使用来自主题的消息:
public void onMessage(Message message )
{
try
{
// try my conversion
}
catch(MyConversionException e)
{
//catch conversion error but still consume off topic
}
//Any other error i.e. runtime errors will not cause the message to be consumed from topic. So it can be retried
}我希望能够尝试将消息转换为另一个对象。如果这导致错误,我将用自己的异常处理来捕获它,并将其写入错误队列。
我的问题是,如何将Springs bean设置为事务性的,并且只有在成功执行时才会使用?
到目前为止,编辑是bean:
<!-- MESSAGE LISTENER CONTAINER -->
<bean id="ListenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="messageListener" ref="MessageListener" />
<property name="connectionFactory" ref="Tcf" />
<property name="destinationResolver" ref="JmsDestinationResolver" />
<property name="receiveTimeout" value="${jms-timeout}" />
<property name="destinationName" value="${jms-topic}" />
<property name="concurrency" value="1" />
<property name="pubSubDomain" value="true" />
<property name="subscriptionDurable" value="${jms-durable-flag}"/>
<property name="durableSubscriptionName" value="${jms-durable-name}" />
<property name="clientId" value="${jms-client-id}"/>
</bean> 发布于 2012-02-07 17:38:17
不建议这样做,但可以调用TransactionStatus.setRollbackOnly()。
此外,您可能想要考虑与事务模型一致,如果您想回滚,那么通过一个异常.那样的话..。您需要抛出一个RuntimeException,以便Spring回滚消息,如果捕获异常并只记录它,Spring就不知道出了什么问题.
https://stackoverflow.com/questions/9179559
复制相似问题