Queue
A Queue is a message storage mechanism that follows the First In, First Out (FIFO) processing pattern in its basic configuration.
Example:
Dynamics 365
Account createdAzure Service Bus Queue
AccountCreatedQueue
Azure Function
Service Bus TriggerExternal ERP API
Process Account information3. Queue vs Topic
This is a very common interview question.
Queue | Topic |
|---|---|
Point-to-point messaging | Publish-subscribe messaging |
One logical consumer processes each message | Multiple subscriptions can receive copies |
Suitable for one processing workflow | Suitable for multiple independent workflows |
Example:
Suppose an Account is created in Dynamics 365.
We need to notify three systems:
ERP system
Notification system
Data warehouse
A Service Bus Topic can publish one message, and three subscriptions can independently receive it.
4. Create a Service Bus Trigger in C#
Let's see how we consume messages.
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace DemoFunction
{
public class AccountFunction
{
private readonly ILogger<AccountFunction> _logger;
public AccountFunction(ILogger<AccountFunction> logger)
{
_logger = logger;
}
[Function("AccountFunction")]
public void Run(
[ServiceBusTrigger(
"accountcreatedqueue",
Connection = "ServiceBusConnection")]
string message)
{
_logger.LogInformation(
$"Received message: {message}");
}
}
}Understand the important parts
ServiceBusTrigger: Listens for messages in Service Bus.accountcreatedqueue: Queue name.Connection: Name of the application setting containing the connection configuration.message: Incoming message payload.ILogger: Used for logging.
In Azure, configure the ServiceBusConnection application setting, or use an appropriate identity-based connection configuration.
You also need the Microsoft.Azure.Functions.Worker.Extensions.ServiceBus NuGet package for the isolated worker model.
5. What happens if Azure Function fails?
This is an important architect-level question.
Suppose the Function receives a message but the ERP API is unavailable.
What happens?
Azure Service Bus uses message-locking and settlement mechanisms.
The message is typically received under a lock.
If processing succeeds, the message is completed.
If processing fails without successful settlement, the message can become available for redelivery after the lock expires.
After configured delivery attempts are exceeded, the message can move to the Dead-Letter Queue (DLQ).
Dead-Letter Queue: A place where messages are stored when they cannot be successfully processed or are explicitly dead-lettered.
