Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

java - Setting timeout for IBM MQ

When I call com.ibm.mq.MQQueue#put(MQMessage,MQPutMessageOptions) it may hang. How can I set up a timeout for this method? The same question is for com.ibm.mq.MQQueue#get(MQMessage,MQGetMessageOptions)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is MQGMO_WAIT option and a WaitInterval that can be set to make the Get call to wait for a certain amount of time. For example, the following snippet makes the Get call to wait for 3 seconds.

        MQGetMessageOptions gmo = new MQGetMessageOptions();
        gmo.Options = MQConstants.MQGMO_WAIT;
        gmo.WaitInterval = 3000;

        mqQueue.Get(mqMessage, gmo);

There is no option to set a timeout for the Put call though. The Put call returns with an error if there is any issue.

UPDATE:

When a Put call is invoked, connection to queue manager is already established. If there are any issues with the connection, the Put call gets returns soon as the TCP stack notifies of such issue. As such TCP level issues affect the all applications running on the system, in my opinion, tuning must be done at the system level and not at a per application level. Also I don't think it's possible to set a timeout for a socket.write call.

MQ does provide a way set a timeout for establishing connection to queue manager though. There is connection_timeout parameter in mqclient.ini you can set a timeout.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...