Reputation: 22516
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
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