Spring jmstemplate属性配置

时间:2015-07-26 02:05:53

标签: java spring jmstemplate

我正在使用Spring JmsTemplate和JBOSS MQ。我是否需要在jmsTemplate配置文件中使用“sessionTransacted”属性?如果我不单独配置它,那么默认值是什么?

1 个答案:

答案 0 :(得分:0)

您的配置可以是这样的:

   <!-- this is the Message Driven POJO (MDP) -->
<bean id="messageListener" class="jmsexample.ExampleListener" />

<!-- and this is the message listener container -->
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="destination" ref="destination"/>
    <property name="messageListener" ref="messageListener" />
    <property name="sessionTransacted" value="true" />
   <property name="concurrentConsumers" value="5" />
</bean>

您的javax.jms.MessageListener实现应该被构造为重新抛出异常以便通知失败:

  public void onMessage(final Message message) {

        LOGGER.debug("MessageReceiver::onMessage started");
        try {
          //do you service related operations here 
        } catch (Exception ex) {
            LOGGER.error("Error while performing popration", ex);

            throw new RuntimeException("Exception in procesing message");
        }
        LOGGER.debug("MessageReceiver::onMessage completed");

    }