简体   繁体   English

Windows Azure服务总线队列 - MessageSender或QueueClient?

[英]Windows Azure Service Bus Queues - MessageSender or QueueClient?

Backstory: 背景故事:

A few months ago (when I was new to Azure Queues and the SDK tools out there) I Googled "how do I do this" and "how do I do that"... here is where I am today: 几个月前(当我不熟悉Azure Queues和SDK工具时)我用Google搜索“我该怎么做”和“我该怎么做”......这就是我今天所处的位置:

  1. I'm using a QueueClient (Microsoft.ServiceBus.Messaging - Microsoft.ServiceBus.dll) to receive messages from an Azure Queue. 我正在使用QueueClient (Microsoft.ServiceBus.Messaging - Microsoft.ServiceBus.dll)从Azure队列接收邮件。

  2. In my same program I'm also using a MessageSender (from the same namespace and dll) to send messages to the Azure Queue. 在我的同一个程序中,我还使用MessageSender (来自相同的命名空间和dll)将消息发送到Azure队列。

  3. My program has to track a Dictionary<string, QueueClient> and a Dictionary<string, MessageSender> - which is more complicated than it should be. 我的程序必须跟踪Dictionary<string, QueueClient>Dictionary<string, MessageSender> - 这比它应该更复杂。

Now that I'm more familiar with the Azure SDKs... I realize that the QueueClient class can both send and receive ... So why am I keeping track of 2 objects when the first one can do both? 现在我对Azure SDK更熟悉了......我意识到QueueClient类可以发送和接收 ......那么为什么我要跟踪2个对象,而第一个可以同时执行这两个对象?

Question: 题:

Is there any reason to use the MessageSender class instead of the QueueClient class? 是否有任何理由使用MessageSender类而不是QueueClient类?

If I need to send and receive, shouldn't I just use the QueueClient class? 如果我需要发送和接收,我不应该只使用QueueClient类吗?

We have exposed the two different object to support symmetry and ease-of-use. 我们已经暴露了两个不同的对象,以支持对称性和易用性。 As you are aware we have Topics/Subscriptions as well as Queues . 如您所知,我们有主题/订阅以及队列 If you are just using Queues then you can create a QueueClient and achieve all the operations needed thru that. 如果您只是使用队列,那么您可以创建QueueClient并实现所需的所有操作。 But say you later wanted to move to a Topic/Subscription publish-subscribe model. 但是,您后来想要转向主题/订阅发布 - 订阅模型。 Programming against a generic MessageSender and MessageReciever will allow you to change the underlying topology and not have to modify any code (just the address urls/names ). 针对通用MessageSenderMessageReciever进行编程将允许您更改基础拓扑,而不必修改任何代码(只是地址URL /名称 )。 Thus you can write code that can work both in Queue as well as Topic/Subscription scenarios. 因此,您可以编写可在Queue以及主题/订阅方案中使用的代码。

OK - I should have just reflected the DLL first... found the answer. 好的 - 我应该首先反映DLL ...找到答案。

QueueClient is a class that simply has a MessageSender object and a MessageReceiver object inside of it. QueueClient是一个只有一个MessageSender对象和一个MessageReceiver对象的类。 So the answer is "No, you should not have 2 objects to do the same thing" . 所以答案是“不,你不应该有两个对象来做同样的事情”

Reflected code of the "Send" method: “发送”方法的反映代码:

public void Send(BrokeredMessage message)
{
    this.ThrowIfSenderNull("Send");
    this.InternalSender.Send(message);
}

The "InternalSender" object above is of type MessageSender . 上面的“InternalSender”对象是MessageSender类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 取消长期运行接收的Azure Service Bus QueueClient? - Cancel an Azure Service Bus QueueClient long running Receive? MessageLockLostException中断服务总线QueueClient - MessageLockLostException breaks Service Bus QueueClient 使用Azure Service Bus创建队列的MassTransit 3 - MassTransit 3 with Azure Service Bus creating queues MassTransit在天蓝色服务总线上创建队列 - MassTransit creates queues on azure service bus Azure服务总线队列-当消息在队列中时,QueueClient.Receive()返回空的BrokeredMessage - Azure Service Bus Queue - QueueClient.Receive() returning null BrokeredMessage when messages are in the queue 如何测试QueueClient是否可以成功连接到Azure服务总线队列? - How can I test if QueueClient can successfully connect to an Azure Service Bus Queue? 调用QueueClient.CreateFromConnectionString时使用C#的Azure服务总线队列:BadImageFormatException - Azure Service bus Queue using C# : BadImageFormatException when calling QueueClient.CreateFromConnectionString Windows Azure QueueClient建议使用缓存吗? - Windows Azure QueueClient recommended cache? Azure Service Bus中死信队列中的邮件是否过期? - Do messages in dead letter queues in Azure Service Bus expire? 过期时间过后,Azure Service Bus队列中的消息仍保留在队列中 - Messages in Azure Service Bus Queues remain in queue after expire time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM