DEV Community

Kim CH
Kim CH

Posted on

Azure Service Bus Recap

What is

  • A fully managed enterprise message broker with message queues and publish-subscribe topics



  • First In, First Out (FIFO) message delivery to one or more competing consumers
  • Only one message consumer receives and processes each message

Receive modes

Receive and delete

  • Service Bus receives the request from the consumer, it marks the message as being consumed and returns it to the consumer application.
  • It works best for scenarios in which the application can tolerate not processing a message if a failure occurs.
  • Scenario:
    • The consumer issues the receive request and then crashes before processing it.
    • As Service Bus marks the message as being consumed, the application begins consuming messages upon restart.
    • It will miss the message that it consumed before the crash.

Peek lock

  • In this mode, the receive operation becomes two-stage, which makes it possible to support applications that can't tolerate missing messages.

    1. Finds the next message to be consumed, locks it to prevent other consumers from receiving it, and then, return the message to the application.
    2. After the application finishes processing the message, it requests the Service Bus service to complete the second stage of the receive process. Then, the service marks the message as being consumed.
  • Scenario 1: If the application is unable to process the message for some reason

    • It can request the Service Bus service to abandon the message.
    • Service Bus unlocks the message and makes it available to be received again, either by the same consumer or by another competing consumer.
    • Secondly, there's a timeout associated with the lock. If the application fails to process the message before the lock timeout expires, Service Bus unlocks the message and makes it available to be received again.
  • Scenario 2: If the application crashes after it processes the message, but before it requests the Service Bus service to complete the message

    • Service Bus redelivers the message to the application when it restarts.
    • This process is often called at-least once processing. That is, each message is processed at least once. However, in certain situations the same message may be redelivered.
    • If your scenario can't tolerate duplicate processing, add additional logic in your application to detect duplicates.

Topics and subscriptions

  • Provide a one-to-many form of communication in a publish and subscribe pattern.

    • Publishers send messages to a topic in the same way that they send messages to a queue.
    • But, consumers don't receive messages directly from the topic. Instead, consumers receive messages from subscriptions of the topic.
    • Consumers receive messages from a subscription identically to the way they receive messages from a queue because topic subscription resembles a virtual queue.
  • Each published message is made available to each subscription registered with the topic.

  • Flows:

    • Publisher sends a message to a topic.
    • One or more subscribers receive a copy of the message, depending on filter rules set on these subscriptions.


  1. Service Bus queues, topics, and subscriptions
  2. azure-service-bus-queues-vs-topics

Discussion (0)