本文介绍了为什么要使用QueueClient与MessageFactory?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure Service Bus中,可以使用QueueClientMessageFactory发送代理消息.我想知道您为什么要在另一个上使用一个.

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.

推荐答案

Azure Service Bus提供了不同的发送/接收消息的方法.

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

  • 您可以使用QueueClient向队列发送消息或从队列接收消息.
  • 您可以使用TopicClient将消息发送到主题
  • 您可以使用SubscriptionClient接收来自订阅的消息.
  • 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.

使用MessageSenderMessageReceiver,创建实体类型不变的发送者和接收者:

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

var factory = MessagingFactory.CreateFromConnectionString("MyConnectionString");

  • MessageSender可以将消息发送到主题或队列:

    • A MessageSender can send messages to both topic or queue:

      var sender = factory.CreateMessageSender("Queue ou topic path");
      

    • A MessageReceiver ca从队列和订阅中接收消息:

    • A MessageReceiver ca receive messages from both queue and subscription:

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

    • 如果您需要从队列切换到主题(反之亦然),则这些抽象可以为您提供更大的灵活性,因为您只需要更改服务总线实体的路径(可以在配置文件中),因此无需更改代码需要.如果要从队列移至主题,则必须使用QueueClientTopicClientSubscriptionClient更改代码.

      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.

      因此,我的建议是,当您必须从Azure ServiceBus队列主题/订阅发送消息或从Azure ServiceBus队列主题/订阅接收消息时,请始终使用MessageReceiver/MessageSender.

      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.

      注意:这不适用于具有不同实现的Eventhub.

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

      这篇关于为什么要使用QueueClient与MessageFactory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 11:18