[英]Azure Service Bus SubscriptionClient.OnMessage always completes message when it shouldnt
I am trying to receive all messages for a given subscription to a Service Bus Topic, but for the context of this app I do not want them dead lettered at this time, I just want to view them and leave them on the subscription. 我正在尝试接收给定订阅服务总线主题的所有消息,但是对于此应用程序,我不希望它们此时处于死信状态,我只想查看它们并将其保留在订阅中。 Despite instantiating the Client as 尽管将Client实例化为
SubscriptionClient sc = SubscriptionClient.CreateFromConnectionString(connectionString, sub.topicName, sub.subscriptionName, ReceiveMode.PeekLock);
and making sure that I am using message.Abandon() rather than message.Complete() the message always gets Dead-lettered after accessing the message. 并确保我使用的是message.Abandon()而不是message.Complete(),访问该消息后,该消息始终变为死字母。 I also have options.AutoComplete set to false 我也有options.AutoComplete设置为false
full method code below: 完整的方法代码如下:
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;
}
Am I missing something ? 我想念什么吗? Or is there an issue with auto dead-lettering with the onMessage() method? 还是使用onMessage()方法进行自动死信有问题?
Thanks ! 谢谢 !
When a message is abandoned the service bus will immediately make it available for re-delivery to any subscriber of the topic. 当一条消息被放弃时,服务总线将立即使其可重新发送给该主题的任何订户。
If you are trying to configure a multicast mechanism in which multiple listeners all receive the same message, then understand that all listeners on a given subscription will be competing for the same message. 如果您尝试配置一个多播机制,其中多个侦听器都收到同一条消息,那么请了解给定订阅上的所有侦听器将争夺同一条消息。 In order for every listener to receive its own copy of the message, then simply create a unique subscription to the topic for each listener. 为了使每个侦听器都能收到自己的消息副本,然后只需为每个侦听器创建对该主题的唯一订阅。
If your intent is to delay re-delivery of the abandoned message, you might look at the SO question: 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? 如果您打算延迟重新发送被遗弃的邮件,则可以考虑以下问题: 丢弃Azure SB邮件以便将来以我可以控制的方式再次显示的正确方法是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.