【发布时间】: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