Azure Service Bus is a message broker that carries messages between application and services. It helps in decoupling application and services along with following benefits
- Load balancing
- Data Security
- High reliability
The core message entities in Azure Service bus are Queues, topics and subscriptions.
Let’s discuss how Queue helps in the message processing.
In Service Bus queue, producer sends a message to the queue and can continue its processing without waiting for consumers response. Meanwhile consumer can consume message from the queue and process it. Messages will be processed in First In First Out model, where consumers will be processing in the order i which they were added to the queue.
Prerequisite
Azure account
Azure.Messaging. Service Bus,Azure.Identity; to be installed in the .NET solution.
1.Create an Azure ->Service Bus ->Create Namespace
With in service bus, user can create Queue,Topics and subscription.
Queue can be created with “Basic plan ” subscription, whereas Topic and subscription can be created only with higher plan.
2. Here’s a simple example of how you can achieve this using Azure Service Bus Queue for messaging in .NET. We will create two solutions: one for sending messages to the queue and another for receiving messages from the queue.
client = new ServiceBusClient(<EndPoint>)
Subscriber Connection:
sender = client.CreateSender(“<Queue name>”);
sender.SendMessagesAsync -> is used to send the batch message.
Publisher Connection:
processor = client.CreateProcessor(“<Queue name>”, new ServiceBusProcessorOptions());
processor.StartProcessingAsync(); -> is used to receive and process the message from the queue.
The system processes messages in a First In First Out (FIFO) model. Consumers handle the messages in the order in which they add them to the queue.
The subscriber(processor) application will be listening to the queue. Whenever message comes to the queue, subscriber process the message from the queue.
Subscriber solution starts processing the message from the queue and the active count in the queue becomes 0.
References
https://github.com/DhivyaBharathiKumarasamy/ToQueue.git
https://github.com/DhivyaBharathiKumarasamy/FromQueue.git
Compare Azure Storage queues and Service Bus queues – Azure Service Bus | Microsoft Learn
Understanding Routing in ASP.NET Core MVC – Athen
Hope this blog helps in understanding the Azure Queue implementation.
No Comment! Be the first one.