Azure ServiceBus in .NET Core 2.0

Problem

How to use Azure Service Bus in .NET Core.

Solution

Create a class library and add NuGet package: Microsoft.Azure.ServiceBus

Add a class to encapsulate settings:

Add a class to wrap functionality of sending messages to queue:

Add a class to wrap functionality of receiving messages from the queue:

Now you can use these wrapper classes to send message:

And receive messages:

NOTE: the sample code also include wrappers for topics and subscriptions.

Discussion

The sample code will require you to setup Azure account and Service Bus. Instructions for these could be found at: https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-create-namespace-portal

Source Code

GitHub: https://github.com/TahirNaushad/Fiver.Azure.ServiceBus

Leave a Reply