Azure Service Bus provides another way to send / receive messages.
- You can use
QueueClient to send and receive messages to / from the queue. - You can use
TopicClient to post to a topic - And you can use
SubscriptionClient to get the message from the subscription.
Using MessageSender and MessageReceiver , you create a sender and a receiver, which are invariants of the object type:
var factory = MessagingFactory.CreateFromConnectionString("MyConnectionString");
A MessageSender can send messages to both the thread and the queue:
var sender = factory.CreateMessageSender("Queue ou topic path");
A MessageReceiver ca to receive messages from the queue and subscription:
var receiver = factory.CreateMessageReceiver("Queue ou subscription path");
Abstracts of abstracts can give you more flexibility if you need to switch from a queue to a topic or vice versa, because you just need to change the path to the service bus object (this may be in your configuration file), so changing the code is necessary. Using QueueClient , TopicClient , SubscriptionClient , you will need to change your code if you want to switch from a queue to a topic.
So my advice is to always use MessageReceiver / MessageSender when you need to send / receive messages from / to a topic / subscription to Azure ServiceBus.
NOTE. This does not apply to Eventhub, which has a different implementation.
source share