[英]Windows Azure Service Bus Queues - MessageSender or QueueClient?
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搜索“我该怎么做”和“我该怎么做”......这就是我今天所处的位置:
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队列接收邮件。
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队列。
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个对象,而第一个可以同时执行这两个对象?
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 ).
针对通用MessageSender和MessageReciever进行编程将允许您更改基础拓扑,而不必修改任何代码(只是地址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" . 所以答案是“不,你不应该有两个对象来做同样的事情” 。
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.