Search code examples
c#.netazureazure-queues

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:

  1. I'm using a QueueClient (Microsoft.ServiceBus.Messaging - Microsoft.ServiceBus.dll) to receive messages from an Azure Queue.

  2. In my same program I'm also using a MessageSender (from the same namespace and dll) to send messages to the Azure Queue.

  3. My program has to track a Dictionary<string, QueueClient> and a Dictionary<string, MessageSender> - which is more complicated than it should be.

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?

Question:

Is there any reason to use the MessageSender class instead of the QueueClient class?

If I need to send and receive, shouldn't I just use the QueueClient class?


Solution

  • OK - I should have just reflected the DLL first... found the answer.

    QueueClient is a class that simply has a MessageSender object and a MessageReceiver object inside of it. 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.