简体   繁体   中英

IBM MQ XMS with .NET Core 3.1 - how fetch messages already existing on topic?

Im trying to consume messages from WMQ from my .NET Core worker service. I get it to work if I start my service and then publish messages on queue, but my service ignores all already existing messages. I read about durable subscribers, but that does not seem to quite be what Im after.

currently using nuget : IBMXMSDotnetClient, 9.2.0.1

code:

var destinationName = _apexConsumerOptions.Destination;

var isTopic = destinationName.StartsWith("topic://");

destinationName = destinationName.Remove(0, 8);

_connectionWmq = CreateConnection();

_sessionWmq = _connectionWmq.CreateSession(false, AcknowledgeMode.ClientAcknowledge);

_destination = isTopic ? _sessionWmq.CreateTopic(destinationName) : _sessionWmq.CreateQueue(destinationName);

_consumer = _sessionWmq.CreateConsumer(_destination);

_connectionWmq.Start();

while (!stoppingToken.IsCancellationRequested)
{
    //  fetch message
    var message = _consumer.Receive(_apexConsumerOptions.Timeout);

    HandleMessage(message);
    await Task.Delay(_apexConsumerOptions.MillisecondsBetweenSyncPolls, stoppingToken);
}
_connectionWmq.Close();

I'm trying to subscribe to topic, not queue.

I also have issues with MessageListener only activating on first message posted, but that seems to be known issue with 9.2.

Ultimately it was a durable subscriber I was after, so implementing that solved my issue.

link to docs @ ibm about durable subscribers : https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.2.0/com.ibm.mq.dev.doc/xms_csub_dur.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM