|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
IBM MQ get more than 4000 messages |
« View previous topic :: View next topic » |
Author |
Message
|
pera_nv |
Posted: Mon Sep 11, 2023 4:15 pm Post subject: IBM MQ get more than 4000 messages |
|
|
Newbie
Joined: 11 Sep 2023 Posts: 1
|
I'm trying to read 5,000 messages but it takes 8-10 minutes, can someone guide me? this is my code
Code: |
public Task<PlainAllMessageByQueueNameQueryResult> GetAllByQueueName(string queueName, int pageNumber, int pageSize,
int idUsuario,string organism, string queueNameOrigin ,CancellationToken cancellationToken)
=> Task.Run(async () =>
{
var messageQueue = new PlainAllMessageByQueueNameQueryResult();
messageQueue.QueueName = queueName;
messageQueue.Data = new List<Application.Features.Security.Dto.MessageMq>();
var queueDepth = 0;
using var queueManager = CreateQueueManager();
try
{
var hoursUtc = - int.Parse(this._configuration["CatalogosIrdoc:UtcIbmMq:Hours"]);
var queue = queueManager.AccessQueue(queueName.TrimStart().TrimEnd(), MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE);
if (queue.CurrentDepth.Equals(0))
throw new InvalidOperationException($"Sin mensajes en {queueName}");
var counter = queue.CurrentDepth;
queueDepth = queue.CurrentDepth;
for (int i = 0; i < queueDepth; i++)
{
var queueMessage = new MQMessage();
queueMessage.Format = MQC.MQFMT_STRING;
var messageOptions = new IBM.WMQ.MQGetMessageOptions();
messageOptions.Options = MQC.MQGMO_BROWSE_NEXT; // MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;
queue.Get(queueMessage, messageOptions);
var strReturn = queueMessage.ReadBytes(queueMessage.MessageLength);
var messageId = BitConverter.ToString(queueMessage.MessageId).Replace("-", "");
messageQueue.Data.Add(new Application.Features.Security.Dto.MessageMq {
Message = Encoding.UTF8.GetString(strReturn),
MessageId = messageId.ToString(),
QueueName = queueNameOrigin,
Date = queueMessage.PutDateTime.AddHours(hoursUtc).ToString("yyyy/MM/dd HH:mm")
});
}
messageQueue.RecordsTotal = counter;
queue.Close();
await _addRegisterRepository.AddRegister(idUsuario, organism, queueName, $"{MenuNames.MessagesMQ.Value}",
$"{ActionsRegisterName.LEER.Value}", "",
"", "", "", null, cancellationToken, null);
}
catch (Exception)
{
}
finally
{
queueManager.Close();
queueManager.Disconnect();
}
return messageQueue;
}, cancellationToken);
|
|
|
Back to top |
|
 |
gbaddeley |
Posted: Tue Sep 12, 2023 3:09 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
It should probably run much faster than what you observed. Is it using MQ Client connection over a slow network link? What is the message size?
Is there any reason why it's getting a fixed number of messages, based on the current queue depth at the start of the loop?
Typically an app would loop until the "get" generates an exception "no message available", or it would use the "wait interval" feature to block until new messages are available on the queue. _________________ Glenn |
|
Back to top |
|
 |
hughson |
Posted: Tue Sep 12, 2023 10:27 pm Post subject: |
|
|
 Padawan
Joined: 09 May 2013 Posts: 1959 Location: Bay of Plenty, New Zealand
|
Do you know where in your program the time is spent?
For example, if you capture timestamps at the points in the code where the most interesting things happen, you would be able to narrow down what in your program would be taking the most time.
I imagine capturing timestamps around these two lines within your for loop would be a good starting point.
Code: |
queue.Get(queueMessage, messageOptions); |
Code: |
messageQueue.Data.Add(... |
Cheers,
Morag _________________ Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|