问题
Yesterday I was able to repeatedly read messages from a subscription of an Azure Service Bus Topic that I created myself. Today, however, whilst using the same code as yesterday, all messages are null despite that the message count of the subscription is well above 0. Let me elaborate:
Following the instruction on the MSDN site concerning how to read messages from subscription , I'm using the following to read messages from a subscription client:
var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider("MySubscriber","MyKey");
var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", "MyNamespace", string.Empty);
var messagingFactory = MessagingFactory.Create(serviceUri, tokenProvider);
var subscriptionClient = messagingFactory.CreateSubscriptionClient("MyTopicName", "MySubscriptionName", ReceiveMode.PeekLock);
var brokeredMessage = subscriptionClient.Receive();
Today, the brokeredMessage variable is always null, but as you can see from the following screenshot, there are several messages in the subscription.
So why does brokeredMessage == null?
The settings of the topic have been set in the management portal and are: Default message time to live = 1 hour, duplicate detection history = 10 min, filter message before publishing not set, topic state = enabled, and no shared access policies.
Likewise for the subscription, the settings are: Default message time to live = 10 min, Lock duration = 5 sec, Maximum delivery count = 10, Topic subscription state = Enabled, and none of the checkboxes concerning moving messages have been checked.
I'd be grateful for any ideas.
回答1:
I've found a solution to the problem; simply delete the subscription and re-add it. That is, however, why I couldn't read the messages. The following thread on stackoverflow leads me to believe that the messages were dead-lettered, despite the screenshot showing otherwise.
If I figure out the reason for the problem, I will update this answer.
来源:https://stackoverflow.com/questions/21748292/receiving-message-from-azure-topic-yields-null-topic-has-unread-messages