【发布时间】:2021-02-17 07:13:19
【问题描述】:
我正在尝试从我的 .NET Core 辅助服务中使用来自 WMQ 的消息。如果我启动我的服务然后在队列上发布消息,我可以让它工作,但我的服务会忽略所有已经存在的消息。我读过关于持久订阅者的文章,但这似乎不是我所追求的。
当前使用 nuget:IBMXMSDotnetClient, 9.2.0.1
代码:
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();
我正在尝试订阅主题,而不是队列。
我也有 MessageListener 仅在发布的第一条消息时激活的问题,但这似乎是 9.2 的已知问题。
【问题讨论】:
-
IBM MQ 订阅者不会收到在创建订阅之前发布的消息。唯一的例外是保留的发布/订阅,但在这种情况下,只有保留的最新发布才能提供给新订阅者。非持久和持久之间的区别在于,您可以恢复持久订阅并接收自上次连接以来发布的所有消息。如果您希望能够在订阅之前订阅并获取数据,那么您需要查看 Kafka (IBM Event Streams) 之类的东西。
标签: c# asp.net-core .net-core ibm-mq xms