4
votes

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.

3
I'm familiar with ActiveMQ rather than IBM MQ, but ActiveMQ allows you to set a timeout if a send fails because it can't connect to the broker by allowing you to specify a timeout value in the failover configuration of your ConnectionFactory. IBM MQ may have a similar capability. AMQ also has a sendFailIfNoSpace configuration parameter that will have the broker return a failure message if the broker is unable to store the message due to space constraints, rather than blocking indefinitely waiting for space to become available. Again, IBM MQ may have something similar.Tim
yes i saw many articles on google related to activemq by apache but not ibm , i think people rarely uses it but its our clients requirements :(anshulkatta
Are these timeouts normal and expected? Should they be happening (in which case, clearly you need to write code that will handle them), or does the fact that you're seeing them really indicate some of the problem (e.g. your broker has some equivalent of AMQ's producer flow control enabled and you've configured the broker with too little storage space - memory or disk or both)? Maybe there are broker config changes that will make it not matter that you can't set a timeout on sending messages? Or if the problem is that the broker is down, maybe you can use clustering to improve availability.Tim
I would go with Roger's answer. Are you using JNDI bindings file created by the mq JMSAdmin tool? If you are using a wrong queue (deliberately for testing purposes) and added it in the JNDI bindings file, MQ qmgr when binding to the queue in realtime will throw 2085 unless you are using other ways (like a qmgr alias, in that case it will end up in the target qmgrs DLQ). MQ exceptions are stored in the linked exception. Also try the latest fixpack of the mq version.Umapathy
Try and see what happens if you call the websphere mq classes for jms directly, with an incorrect destination, and get that to work properly, before fixing the spring configuration.flup

3 Answers

1
votes

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.

0
votes

@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

0
votes

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.