Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22516

Websphere MQ - MQQueueManager, keep it open or close after every connection

I have a C# application that connects to a Websphere MQ.

Basically:

 MQEnvironment.Hostname = HostName;
 MQEnvironment.Channel = Channel;
 MQEnvironment.Port = Port;
 MQQueueManager queueManager = new MQQueueManager(QueueManagerName);

 using (MQQueue putQueue = queueManager.AccessQueue(putQueueName, MQC.MQOO_OUTPUT))
 { 
 }

My question is: Should I create only one instance of the MQQueueManager for the whole application and reuse it everytime I want to put a message or create new MQQueueManager object(connection) for every call?

Upvotes: 1

Views: 3392

Answers (1)

Shashi
Shashi

Reputation: 15283

Unless your are sharing connections, create MQQueueManager instance once per thread and keep it as long as you need, call the Disconnect method when your job is done. Don't keep the instance till end of your application.

Similarly for queue, open queue once and keep putting/getting messages and once job done, close the queue.

Read this article ob MQ Best practices: http://www.ibm.com/developerworks/websphere/library/techarticles/0807_hsieh/0807_hsieh.html

Upvotes: 2

Related Questions