Service Bus
- It can work in two different ways:
Sender-> Queue ->Receiver(Basic, Standard, Premium)Publisher-> Topic ->Subscribers(Standard, Premium)- The service bus receives a namespace name
- E.g.,
Connection strings
- For queues and topics:
Shared access policies(RootManageSharedAccessKey) - For one queue only:
Queues/Shared access policies-> Add - For one topic only:
Topics/Shared access policies-> Add
Good practices
-
Client
-
Service Bus Client connection are defined as the type
IQueueClient- In the background these clients make use of
MessagingFactoryobject
- In the background these clients make use of
-
Do not close connection directly after sending or receiving message
- The connection operation is an expensive operation
- Use the same client for multiple operations!
-
Client batching
-
Delays the send of message and then many at once as a batch
- Increases the throughput
-
Do not use batching if you need low latency
-
Batched store access
-
The queue itself batches multiple messages before writing to the internal store
-
Enable Prefetch
-
Receiver quietly more messages than it's told to and buffer it for latter use
- Reduces the latency
- Defined in
QueueClient.PrefetchCountandSubscriptionClient.PrefetchCount - Does not work well with
ReceiveAndDelete, because the app can crash and the messages will be lost