-1

我正在开发一个 Azure Service Fabric 项目,该项目使用 Apache.NMS .NET 库从 ActiveMQ 读取消息,并创建持久的消费者以从 ActiveMQ 中读取特定消息。

我能够阅读该消息并且一切正常,但我收到如下警告。

'System.RAP' reported Warning for property 'IStatelessServiceInstance.OpenDuration'. The api IStatelessServiceInstance.Open on node _Node_0 is stuck.

此警告会导致服务出错,因此我需要删除该警告。

任何人为什么它给我警告。

这是我如何阅读消息的快照。

try
{
    ITopic dest = AMQSession.GetTopic(TopicName);

    using (IMessageConsumer consumer = AMQSession.CreateDurableConsumer(dest, SubscriptionName, MessageSelector, false))
    {
        IMessage message;
        while ((message = consumer.Receive()) != null)
        {
            ITextMessage txtMsg = message as ITextMessage;            
        }
    }
}
catch (Exception ex)
{
    Close();
}
finally
{
    Close();
}
4

1 回答 1

0

这个问题几乎可以肯定是由于您的代码可以永远阻塞。具体来说,consumer.Receive()如果没有消息到达,将永远阻塞。正如文档所述:

等待消息可用并返回

此外,即使消息确实到达,while循环也确保包含方法永远不会返回。

我建议您在尝试使用消息时指定超时。如果超时时间过去,那么Receive将返回null并且循环将被打破并且代码将不再被阻塞。

于 2020-10-09T16:51:21.857 回答