4

我使用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 配置-

<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

4

3 回答 3

1

这都是无意义的。

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

仅使用 JMS 和 MQ 尝试相同的测试,您将看到不同之处。

于 2013-08-08T21:12:37.403 回答
0

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

于 2013-08-20T17:49:48.537 回答
0

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

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

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

于 2017-06-14T11:47:07.683 回答