如果未指定订阅,则发送给主题的消息将会丢失 [英] Messages sent to Topic are getting lost if no subscriptions are specified

查看:104
本文介绍了如果未指定订阅,则发送给主题的消息将会丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure Service Bus中,如果下面是事件的顺序,那么就没事了-

In Azure Service Bus, if below is the sequence of events, then all's fine -

  1. 创建主题
  2. 在主题内创建订阅
  3. 发送消息到主题

使用上面的命令,订阅将在发送消息时触发.这是预期的.

With above, the subscriptions are triggered when a message is sent. This is expected.

但是,如果我们像这样修改上面的序列

However, if we modify the above sequence like this

  1. 创建主题
  2. 发送消息到主题
  3. 在主题内创建订阅

在这种情况下,由于在没有订阅的情况下将消息发送到主题,因此当确实创建订阅时,先前发送的消息不会显示在其列表中.这些消息实质上是丢失"的.也无法在Service Bus Explorer中看到这些消息.

In this case, as messages are sent to a topic whilst no subscriptions were in place, when the subscriptions are indeed created, the previously sent messages don't show up in their list. Those messages are essentially 'lost'. Am not able to see those messages in Service Bus Explorer too.

上面的序列流很重要,因为我们已经分离了发布者和订阅者,其中发布者只是发送一条消息,而订阅者在联机时创建订阅并处理它们.无法保证发布者和订阅者上线的顺序.

The above sequence flow is relevant because we have detached publishers and subscribers, where the publisher just sends a message and subscribers, when they come online, create the subscriptions and handle them. The order in which the publisher and subscriber come online is not guaranteed.

在创建订阅之前,如何访问/处理发送给该主题的消息?首先,这些消息会发生什么?

How can I access/process messages sent to the topic before the subscriptions are created? What happens to such messages in the first place?

谢谢

推荐答案

事实证明,上述行为是设计使然-如果没有订阅,则消息会丢失.

It turns out that the above behavior is by design - if no subscriptions are there, then the message is lost.

为解决此问题,Azure Service Bus提供了一个主题属性,可在发送消息之前启用对消息的预筛选.因此,如果没有可用的过滤器/订阅,它将引发异常

To overcome this, Azure Service Bus provides a property on topic to enable the pre-filtering of messages before they are sent. So, if no filters/subscriptions are available, it'll throw an exception

在主题上设置选项

namespaceManager.CreateTopicAsync(new TopicDescription(topicName)
{
    EnableFilteringMessagesBeforePublishing = true
});

在发送消息时,请检查是否存在异常

Whilst sending the message, check for exception

try
{
    await topicClient.SendAsync(brokeredMessage);
}
catch (NoMatchingSubscriptionException ex)
{
 // handle the exception, maybe send it to dead letter queue using DeadLetterAsync
}

这篇关于如果未指定订阅,则发送给主题的消息将会丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆