public string GetMessage()
{
MQMessage retrievedMessage = new MQMessage()
{
Version = MQC.MQMD_VERSION_2
};
this.queue.Get(retrievedMessage, getMessageOptions);
if (retrievedMessage.DataLength == 0)
{
return string.Empty;
}
var message = retrievedMessage.ReadString(retrievedMessage.DataLength);
return message;
}
this.getMessageOptions = new MQGetMessageOptions
{
Options = MQC.MQGMO_NO_WAIT
| MQC.MQGMO_FAIL_IF_QUIESCING
| MQC.MQGMO_COMPLETE_MSG,
// it is adviced not to use MQC.MQGMO_CONVERT
WaitInterval = 10000,
MatchOptions = MQC.MQMO_NONE
};
public void Connect()
{
this.queueManager = new MQQueueManager(Configuration.ManagerName, Configuration.ToMqHashTable());
// If Browse is ever needed: MQC.MQOO_BROWSE
this.queue = queueManager.AccessQueue(this.Configuration.QueueName, MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_INQUIRE);
}
Above code snippet took form my MqClient class, after connected to the MQ successfully I can fetch the messages from MQ using GetMessage() sample code shown in below
static void Main(string[] args)
{
Console.WriteLine("SATS DataFeeder POC");
dataBuffer = new BufferBlock<string>();
var timer = new Stopwatch();
timer.Start();
int messageCount = 0;
while (true)
{
try
{
if (!IsConnected)
InitializeClient();
var data = client.GetMessage();
dataBuffer.Post(data);
//count = client.CountMessagesInQueue();
messageCount += 1;
Console.WriteLine($"Queue count : {messageCount}");
if (messageCount == 100)
{
timer.Stop();
var totalSeconds = timer.Elapsed.Seconds;
Console.WriteLine("Message Consumption Rate = Total Time taken to consume 100 messages = " + 100 / totalSeconds + " messages/second");
}
}
catch (MQException exc) when (exc.ReasonCode == (int)MQExceptionReasonCodes.MQRC_NO_MSG_AVAILABLE)
{
Console.WriteLine(exc);
}
catch (MQException exc) when (exc.ReasonCode == (int)MQExceptionReasonCodes.MQRC_HOST_NOT_AVAILABLE)
{
Console.WriteLine(exc);
}
catch (MQException exc)
{
Console.WriteLine(exc);
}
catch (Exception exc)
{
Console.WriteLine(exc);
}
}
}
currently it reads 100 messages in 14 seconds and 8 messages per second. This speed is not enough since there are many messages keep adding to the queue in peak times and it raise many MQ threshold exceed alerts. I want a better solution to handle consume speed of my sample application in order to avoid alerts and MQ queue depth reach to 30000 in peak time. the application is using .NET core 3.1 targeted framework and IBM nugget package IBMMQDotnetClient 9.2.5. Please help to solve this issue.