0
votes

I'm using Microsoft.Azure.ServiceBus namespace to connect to a Service Bus topic. I'm looking for a way to retrieve messages from a subscription iteratively as it was possible using the Microsoft.ServiceBus.Messaging namespace? I'm looking for something similar:

SubscriptionClient subscriptionClient = SubscriptionClient.CreateFromConnectionString(ServiceBusConnectionString, TopicName, SubscriptionName);

while(true)
{
    BrokeredMessage brokeredMessage = subscriptionClient.ReceiveAsync().Result;
    var strBody = brokeredMessage.GetBody<Stream>();
    StreamReader streamReader = new StreamReader(strBody);
    Console.WriteLine(streamReader.ReadToEnd());
    brokeredMessage.Complete();
}

AFAIK, Microsoft.Azure.ServiceBus library provides the only option of using subscriptionClient.RegisterMessageHandler which uses the underlying Message Pump.

However, in the event of an outage at the subscriber application and if it needs to read the pending unread messages from the Subscription, it needs to do a Receive or ReceiveAsync

Is my assumption correct?

1

1 Answers

0
votes

Messages can be received from queue/subscription using one of the two methods.

  1. Manually using Receive()/ReceiveAsync() provided by MessageReceiver or
  2. Automatically using message pump provided by QueueClient/SubscriptionClient

Behind the scenes, message pump (aka Message Handler) is using the manual option to receive messages.