Need to understand specific usage of these Namespaces Microsoft.Azure.ServiceBus vs Azure.Messaging.ServiceBus?

Navin Singhwane 26 Reputation points
2021-03-01T13:13:40.677+00:00

Just want to understand in Azure Message Queue. In various examples and references, used different namespaces -

Microsoft.Azure.ServiceBus and Azure.Messaging.ServiceBus

Could you please let me know what are the differences between them?

To understand further, I also read from the below link - https://msft.it/6010VB26q

But still having the same question.

To use Service Bus Queue, need to use the Namespace Azure.Messaging.ServiceBus.

Following the link (https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues).

But on the other end, if I want to use the Message Session feature, How can I do with Azure.Messaging.ServiceBus namespace?

Using C# .NET Core.

Please suggest

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
553 questions
0 comments No comments
{count} vote

Accepted answer
  1. MayankBargali-MSFT 68,746 Reputation points
    2021-03-02T05:10:52.817+00:00

    Hi @Navin Singhwane

    Welcome to Microsoft Q&A! Thanks for posting the question.

    Sharing the previous discussion on the difference between both libraries. You can also refer to this if you are confused about which one to choose while developing your application.

    To use Service Bus Queue you can choose any of the libraries. You can refer here for the service bus samples.
    Azure.Messaging.ServiceBus does expose the Session operation: https://learn.microsoft.com/en-us/dotnet/api/azure.messaging.servicebus?view=azure-dotnet

    You can refer to Sample for processing message from a session enabled queue and for Azure.Messaging.ServiceBus Samples please refer to this.

    Hope the above helps. Feel free to get back to me if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Navin Singhwane 26 Reputation points
    2021-03-02T12:22:59.847+00:00

    Yes, I am following the same by setting up the property IsSessionEnabled to true.

    But how can I get the SessionId?

    Please go through the below ServiceBusTrigger function -

    public static void Run([ServiceBusTrigger("mytqueue", Connection = "QConnection", **IsSessionsEnabled = true**)] string myQueueItem, string messageId, ILogger log)
            {
                log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
                log.LogInformation($"Message Id: {messageId}");
    
                **//log.LogInformation($"Session Id: {sessionId}");** //How to get session information
            }
    

    On the other hand, I am able to get sessionId, if use the below parameters that are associated with Microsoft.Azure.ServiceBus

    public static void Run([ServiceBusTrigger("mytqueue", Connection = "QConnection", **IsSessionsEnabled = true**)] **Message message**, ILogger log)
            {
                log.LogInformation($"C# ServiceBus queue trigger function processed message: {Encoding.UTF8.GetString(message.Body)}");
                log.LogInformation($"Session Id processed message: **message.SessionId**");
            }
    

    Please suggest the correct way to achieve the ServiceBusTrigger with Session Information.