Why use a QueueClient vs MessageFactory?

不羁岁月 提交于 2019-11-30 01:26:11

问题


In Azure Service Bus, you can send a brokered message using QueueClient and MessageFactory. I would like to know why would you want to use one over the other.


回答1:


Azure Service Bus provides different way to send/receive messages.

  • You can use the QueueClient to send and receive message to/from a queue.
  • You can use the TopicClient to send message to a topic
  • And you can use the SubscriptionClient to receive message from a subscription.

Using MessageSender and MessageReceiver, you create sender and receiver that are entity type invariant:

var factory = MessagingFactory.CreateFromConnectionString("MyConnectionString");
  • A MessageSender can send messages to both topic or queue:

    var sender = factory.CreateMessageSender("Queue ou topic path");
    
  • A MessageReceiver ca receive messages from both queue and subscription:

    var receiver = factory.CreateMessageReceiver("Queue ou subscription path");
    

Theses abstractions 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 of the service bus entity (This could be in your configuration file) so no code change needed. Using QueueClient, TopicClient, SubscriptionClient, you'll have to change your code if you want to move from a queue to a topic.

So my advice is to always use a MessageReceiver/MessageSender when you have to send/receive message from/to a an Azure ServiceBus queue topic/subscription.

NOTE: This does not apply for Eventhub which has a different implementation.



来源:https://stackoverflow.com/questions/39186975/why-use-a-queueclient-vs-messagefactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!