JmsTemplate has no send timeout

此生再无相见时 提交于 2019-12-12 16:05:16

问题


I have working JMS application with IBM MQ jars configuration , using spring

It works well with correct queue information , but when i give wrong queue information

it is hung at

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

I have my Log saying sending message , i am handling org.springframework.jmsexception , but it does not throw.....i think it is hung at that point.

I am not able to find any property for jmstemplate for send timeout , only for recieve timeout is there...

Here is jmstemplate conf in app-context.xml (Spring)

<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>

and 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>

I have set it to Auto-acknowledge

this.jmsTemplate.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);

So please tell me how to have timeout on sending message to throw jmsexception.


回答1:


This is all non sense.

If you attempt to put a message to an invalid queue, MQ IMMEDIATELY throws an exception with a reason code 2085 (unknown object). There is no timeout required. Obviously, the framework you are using has a bug in it that it is not catching the thrown exception!!!

Try the same test using just JMS and MQ, and you will see the difference.




回答2:


@anshulkatta why don't you validate the destination before setting it using methods from JmsDestinationAccessor. use the resolveDestinationName method for validation. So your application will validate the destination otherwise it will throw a JMSException which you can catch and log appropriate validation message. check http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jms/support/destination/JmsDestinationAccessor.html




回答3:


Look into Hystrix library. With its help, you can manage the timeout of the connection. Set the timeout into the HystrixCommandProperties.Setter and pass it to HystrixCommand class.

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

Then run execute() method from HystrixCommand class.



来源:https://stackoverflow.com/questions/18128102/jmstemplate-has-no-send-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!