Service Bus Queues and Topics

Service Bus

  • Namespace: Serves as a container for managing queues and topics.

  • Queues: Used for point-to-point communication. When multiple consumers are involved, the queue utilizes the competing consumers pattern to distribute messages.

  • Topics: Support a publish-subscribe model, allowing one topic to have multiple subscriptions. Messages sent to the topic are delivered to all the associated subscriptions.

Features

Duplicate Detection:

By default, duplicate detection is handled using the message ID. If a message with the same message ID is sent again, it will not be added to the queue.

  • With Partition Key: Duplicate detection is based on the combination of message ID and partition key.
  • With Session ID: Duplicate detection is based on the combination of message ID and session ID. The session ID and partition key must be the same.

Scenarios:

  1. If a message with message ID "1" is pushed to the queue and is not processed, pushing another message with the same ID "1" will not add it to the queue.
  2. If a message with ID "1" is pushed to the queue, processed, and then a new message with the same ID "1" is pushed, it will not be added to the queue.

Forwarding Messages to a Queue or Topic:

Messages can be forwarded to a specific topic or queue. Once enabled, the message will be removed from the original queue or topic.

  • Constraint: Forwarding messages is not available for queues with sessions enabled.

Partitioning:

Enabling partitioning in a queue or topic improves availability but does not guarantee message order.

  • Normal Queue or Topic Workflow:

    • Sender → Queue → Messaging Store → Receiver
    • If the messaging store is unavailable, the queue or topic will be inaccessible.
  • Partition-Enabled Queue or Topic Workflow:

    • Sender → Queue → Messaging Store → Receiver
    •                             → Messaging Store → Receiver
    •                             → Messaging Store → Receiver
    • If one messaging store is unavailable, the queue or topic remains accessible due to multiple messaging stores.
  • Constraint: In Basic and Standard tiers, a maximum of 16 partitions can be created. In Premium tier, the number of partitions can be specified during creation.





Session:

Sessions group messages that need to be received in order.

  • Constraint: Sessions are available only for queues, not for topics.



Auto-Delete on Idle:

This feature automatically deletes a queue or topic after it has been idle for the specified period set at creation time.

Dead Lettering on Message Expiration:

Messages are moved to the dead-letter queue once they expire or reach their time-to-live (TTL) limit.

  • Constraint: This feature is supported only for queues.

Assigning Roles:

  • Queues or Topics:

    • To assign roles to a user, group, or managed identity for queues or topics, you can do so directly through the Azure portal.

    • To assign roles to an application, use the Azure CLI.

  • Subscriptions:

    • For assigning roles at the subscription level, you’ll need to use the Azure CLI with the following command:


az role assignment create --role "Azure Service Bus Data Receiver" --assignee $user/group/managedidentity/applicationid --scope /subscriptions/$Subscription/resourceGroups/$resourcegroup/providers/Microsoft.ServiceBus/namespaces/$servicebusnamespace/topics/$topicname/subscriptions/$subscription-name

Scheduled Messages:

You can schedule messages to be sent to a queue at a future time. When you schedule a message, it is placed in the queue but will only be available for consumption once the scheduled time arrives. This allows you to delay the processing of the message until a specified future time.



Deferred Messages:

If you need to delay the processing of a message after it has already been received, you can defer it. When a message is deferred, it remains in the queue but is not immediately available for consumption. Later, you can retrieve deferred messages using their sequence numbers and process them when you are ready.




Batch Operations:

You can send and receive messages in batches, allowing you to group multiple messages together for more efficient processing.



Transactions:

You can perform operations within transactions, either when sending messages to or receiving messages from the queue. This ensures that a series of actions is executed atomically, maintaining data integrity.

Assigning azure service data sender role to the application but we should keep the client secret

Assigning azure service data sender role to the managed identity, we don't required to keep the secret.



UseFull Link: 
https://www.youtube.com/watch?v=BmatDG4yEgI (Partition vs sessions)
https://github.com/RamadossE2313/LearningServiceBusQueueAndTopics 

Comments

Popular posts from this blog

Azure Service Bus Azure CLI Commands

Securing a Web API using Azure AD and Consuming it with Swagger - Step by Step Guide