We have some code to send messages to a queue. It's using the amqmdnet dll version 8.0.0.6.
The queue manager (Queuemanager) is instantiated once at the start of the application and used throughout. As messages are sent, a queue object is created and then closed. Should we create a queue object for each message or is it better to use just one instance? We are writing messages only, no reads.
Here's some code:
public QueueResult Enqueue(string message)
{
QueueResult result;
using (var queue = _queueManager.AccessQueue(_queueName, MQC.MQOO_OUTPUT + MQC.MQOO_INPUT_SHARED + MQC.MQOO_FAIL_IF_QUIESCING))
{
var mqMessage = new MQMessage
{
Format = "MQSTR",
Encoding = 546,
CharacterSet = 437
};
mqMessage.WriteString(message);
var options = CreateOptions();
queue.Put(mqMessage, options);
result = new QueueResult
{
CompletionCode = options.CompletionCode,
ReasonCode = options.ReasonCode
};
queue.Close();
}
return result;
}
public IQueue AccessQueue(string queueName, int openOptions)
{
return new Queue(mqQueueManager.AccessQueue(queueName, openOptions));
}