我有工作JMS应用程序与IBM MQ jars配置,使用spring
它适用于正确的队列信息,但是当我给出错误的队列信息时
它挂在
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。
这都是无稽之谈。
如果您尝试将消息放入无效队列,MQ 会立即抛出异常,原因代码为 2085(未知对象)。不需要超时。显然,您使用的框架有一个错误,它没有捕获抛出的异常!!!
仅使用 JMS 和 MQ 尝试相同的测试,您就会看到差异。
@anshulkatta 为什么不在使用 JmsDestinationAccessor 的方法设置目标之前验证目标。使用resolveDestinationName 方法进行验证。因此,您的应用程序将验证目标,否则它将抛出 JMSException,您可以捕获并记录适当的验证消息。检查http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jms/support/destination/JmsDestinationAccessor.html
查看 Hystrix 库。借助它的帮助,您可以管理连接超时。将超时设置到 HystrixCommandProperties.Setter 中并将其传递给 HystrixCommand 类。
HystrixCommandProperties.Setter commandPropertiesDefaults = HystrixCommandProperties.Setter()
.withExecutionTimeoutInMilliseconds(timeout);
然后运行 HystrixCommand 类中的execute()方法。