Sharpeye500
Sharpeye500

Reputation: 9073

How do I auto-connect IBM MQ client?

I am using the MQ.NET classes of the MQ 7x client, and importing and exporting messages works fine. However, if there is a network disconnect or the remote manager is disconnected, the IBM MQ client doesn't automatically reconnect. I get:

Error: Remote host ' not available, retry later.   

Is there a way to auto-connect and continue processing the message when these kind of issues occur?

There is a property to check the connection of the queue manager:

mqQMgr = new MQQueueManager("My queue manager name" ,"my channel name",",my connection name");

mqQMgr.IsConnected returns true/false, but this doesn't help to auto-connect.

This is what i am using:

   // mq properties
    Hashtable properties = new Hashtable();
    properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);            
    properties.Add(MQC.CONNECTION_NAME_PROPERTY, "connectionName");            
    properties.Add(MQC.CHANNEL_PROPERTY, "channelName");
    properties.Add(MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_RECONNECT_Q_MGR);

    mqQMgr = new MQQueueManager("my queue manager"), properties); //error thrown

I get this error on the above line

IBM MQException caught in send message - reason code - 2046- message -CompCode: 2, Reason: 2046
{"MQRC_OPTIONS_ERROR"}
base {System.ApplicationException}:
{"MQRC_OPTIONS_ERROR"}
CompCode: 2
CompletionCode: 2
Message: "MQRC_OPTIONS_ERROR"
Reason: 2046

Upvotes: 5

Views: 5790

Answers (2)

Shashi
Shashi

Reputation: 15273

Automatic client reconnection is supported by MQ C# client from v7.1 onwards. You have to use MQCNO_RECONNECT or MQCNO_RECONNECT_Q_MGR or MQCNO_RECONNECT_AS_DEF CNO option to enable automatic reconnection. MQ v7.1 ships couple of samples, SimpleClientAutoReconnectPut.cs is one of them. Please refer to the sample for detail.

Simple snippet.

mqQMgr = new MQQueueManager("QM", MQC.MQCNO_RECONNECT,"SVRCONNCHN","localhost(1414)");

Upvotes: 6

Stas
Stas

Reputation: 286

It has been a while I used that, but there were options for auto reconnect: Here you can read a bit more, even though it is Java tailored, the options are also available in C# wrapper: IBM MQ: Automatic Client Reconnection

A good pattern is before you write a message to check if it is connected & reconnect:

if (!mqQMgr.IsConnected) {
   mqQMgr.Connect();
}
mqQMgr.Write(message);

I don't know if that will help you. Good luck!

Upvotes: -2

Related Questions