JmsTemplate没有发送超时

时间:2013-08-08 14:03:30

标签: java spring jms ibm-mq jmstemplate

我使用 spring

使用 IBM MQ jars 配置 JMS应用程序

它适用于正确的队列信息,但是当我提供错误的队列信息时

挂在

LOG.info("SENDING MESSAGE");
jmsTemplate.send(this.getDestination(), messageCreator );  //here

我有我的日志说发送消息,我正在处理org.springframework.jmsexception,但它没有抛出......我认为它是挂在那一点。

我无法找到jmstemplate的任何属性用于发送超时,仅用于接收超时有...

app-context.xml(Spring)中的 jmstemplate conf

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate102">
        <property name="connectionFactory">
            <ref bean="jmsQueueConnectionFactory" />
        </property>
        <property name="destinationResolver">
            <ref bean="jmsDestinationResolver" />
        </property>
        <property name="pubSubDomain">
            <value>false</value>
        </property>
        <property name="receiveTimeout">
            <value>20000</value>

        </property>

ibm mq conf -

<bean id="mqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
        <property name="hostName">
            <value>${queue_hostname}</value>
        </property>
        <property name="port">
            <value>${queue_port}</value>
        </property>
        <property name="queueManager">
            <value>${queue_manager}</value>
        </property>
        <property name="channel">
            <value>${queue_channel}</value>
        </property>
        <property name="transportType">
            <value>1</value>
        </property>
    </bean>

我已将其设置为自动确认

this.jmsTemplate.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);

所以请告诉我如何在发送消息时超时 jmsexception

3 个答案:

答案 0 :(得分:2)

这都没有意义。

如果您尝试将消息放入无效队列,MQ IMMEDIATELY会抛出原因代码为2085(未知对象)的异常。不需要超时。显然,你正在使用的框架中有一个错误,它没有捕获抛出的异常!!!

仅使用JMS和MQ尝试相同的测试,您将看到差异。

答案 1 :(得分:0)

@anshulkatta为什么不在使用JmsDestinationAccessor中的方法设置目标之前验证目标。使用resolveDestinationName方法进行验证。因此,您的应用程序将验证目标,否则它将抛出JMSException,您可以捕获并记录相应的验证消息。检查http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jms/support/destination/JmsDestinationAccessor.html

答案 2 :(得分:0)

查看Hystrix库。在它的帮助下,您可以管理连接的超时。将超时设置为HystrixCommandProperties.Setter并将其传递给HystrixCommand类。

HystrixCommandProperties.Setter commandPropertiesDefaults = HystrixCommandProperties.Setter()
            .withExecutionTimeoutInMilliseconds(timeout);

然后从HystrixCommand类运行execute()方法。