【问题标题】:Azure Service Bus SubscriptionClient.OnMessage always completes message when it shouldntAzure 服务总线 SubscriptionClient.OnMessage 总是在不应该完成的时候完成消息
【发布时间】:2015-09-02 22:33:36
【问题描述】:

我正在尝试接收给定订阅服务总线主题的所有消息,但对于这个应用程序的上下文,我不希望它们此时死信,我只想查看它们并将它们留在订阅中.尽管将客户端实例化为

SubscriptionClient sc = SubscriptionClient.CreateFromConnectionString(connectionString, sub.topicName, sub.subscriptionName, ReceiveMode.PeekLock);

并确保我使用的是 message.Abandon() 而不是 message.Complete() 消息在访问消息后总是会出现死信。我也有 options.AutoComplete 设置为 false

完整的方法代码如下:

public List<ServiceBusMessage> RetrieveSubscriptionMessages(Subscription sub) {
        ServiceBusMessage sbm;
        List<ServiceBusMessage> list = new List<ServiceBusMessage>();
        String connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"].ToString();
        SubscriptionClient sc = SubscriptionClient.CreateFromConnectionString(connectionString, sub.topicName, sub.subscriptionName, ReceiveMode.PeekLock);
        OnMessageOptions options = new OnMessageOptions();
        options.AutoComplete = false;

        sc.OnMessage((message) => {
            try {

                sbm = new ServiceBusMessage() {
                    topicName = sub.topicName, 
                    messageText = message.GetBody<String>()
                };

                list.Add(sbm);
                message.Abandon();
            }

            catch (Exception) {
                message.Abandon();
                throw;
            }

        }, options);

         return list;
    }

我错过了什么吗?或者 onMessage() 方法的自动死信是否存在问题?

谢谢!

【问题讨论】:

  • 好的,所以我挖得更深了,看起来消息由于 MaxDeliveryCountExceeded 错误而被死信,显然有 11 次尝试发送超过默认最大值 10 的每条消息。为什么每条消息都使用 OnMessage 方法传递 11 次,或者这是一个红鲱鱼? DeliveryAttempts 是否在其他地方设置为 11 以确保消息出现死信?

标签: c# azure azureservicebus


【解决方案1】:

当消息被放弃时,服务总线将立即使其可用于重新传递给该主题的任何订阅者。

如果您尝试配置多播机制,其中多个侦听器都接收相同的消息,那么请了解给定订阅上的所有侦听器将竞争相同的消息。为了让每个侦听器都能收到自己的消息副本,只需为每个侦听器创建一个唯一的主题订阅即可。

如果您的意图是延迟重新发送被遗弃的消息,您可以查看 SO 问题:What's the proper way to abandon an Azure SB Message so that it becomes visible again in the future in a way I can control?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 2023-04-09
    • 2013-03-22
    相关资源
    最近更新 更多