Azure Service Bus

Detailed documentation on the Azure Service Bus pubsub component

Component format

To setup Azure Service Bus pubsub create a component of type pubsub.azure.servicebus. See this guide on how to create and apply a pubsub configuration.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: servicebus-pubsub
  5. namespace: default
  6. spec:
  7. type: pubsub.azure.servicebus
  8. version: v1
  9. metadata:
  10. - name: connectionString # Required
  11. value: "Endpoint=sb://{ServiceBusNamespace}.servicebus.windows.net/;SharedAccessKeyName={PolicyName};SharedAccessKey={Key};EntityPath={ServiceBus}"
  12. # - name: timeoutInSec # Optional
  13. # value: 60
  14. # - name: handlerTimeoutInSec # Optional
  15. # value: 60
  16. # - name: disableEntityManagement # Optional
  17. # value: "false"
  18. # - name: maxDeliveryCount # Optional
  19. # value: 3
  20. # - name: lockDurationInSec # Optional
  21. # value: 60
  22. # - name: lockRenewalInSec # Optional
  23. # value: 20
  24. # - name: maxActiveMessages # Optional
  25. # value: 2000
  26. # - name: maxActiveMessagesRecoveryInSec # Optional
  27. # value: 2
  28. # - name: maxConcurrentHandlers # Optional
  29. # value: 10
  30. # - name: prefetchCount # Optional
  31. # value: 5
  32. # - name: defaultMessageTimeToLiveInSec # Optional
  33. # value: 10
  34. # - name: autoDeleteOnIdleInSec # Optional
  35. # value: 10
  36. # - name: maxReconnectionAttempts # Optional
  37. # value: 30
  38. # - name: connectionRecoveryInSec # Optional
  39. # value: 2
  40. # - name: publishMaxRetries # Optional
  41. # value: 5
  42. # - name: publishInitialRetryInternalInMs # Optional
  43. # value: 500

NOTE: The above settings are shared across all topics that use this component.

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.

Spec metadata fields

FieldRequiredDetailsExample
connectionStringYShared access policy connection-string for the Service BusEndpoint=sb://{ServiceBusNamespace}.servicebus.windows.net/;SharedAccessKeyName={PolicyName};SharedAccessKey={Key};EntityPath={ServiceBus}
timeoutInSecNTimeout for sending messages and management operations. Default: 6030
handlerTimeoutInSecNTimeout for invoking app handler. # Optional. Default: 6030
disableEntityManagementNWhen set to true, topics and subscriptions do not get created automatically. Default: “false”“true”, “false”
maxDeliveryCountNDefines the number of attempts the server will make to deliver a message. Default set by server10
lockDurationInSecNDefines the length in seconds that a message will be locked for before expiring. Default set by server30
lockRenewalInSecNDefines the frequency at which buffered message locks will be renewed. Default: 20.20
maxActiveMessagesNDefines the maximum number of messages to be buffered or processing at once. Default: 100002000
maxActiveMessagesRecoveryInSecNDefines the number of seconds to wait once the maximum active message limit is reached. Default: 210
maxConcurrentHandlersNDefines the maximum number of concurrent message handlers10
prefetchCountNDefines the number of prefetched messages (use for high throughput / low latency scenarios)5
defaultMessageTimeToLiveInSecNDefault message time to live.10
autoDeleteOnIdleInSecNTime in seconds to wait before auto deleting messages.10
maxReconnectionAttemptsNDefines the maximum number of reconnect attempts. Default: 3030
connectionRecoveryInSecNTime in seconds to wait between connection recovery attempts. Defaults: 22
publishMaxRetriesNThe max number of retries for when Azure Service Bus responds with “too busy” in order to throttle messages. Defaults: 55
publishInitialRetryInternalInMsNTime in milliseconds for the initial exponential backoff when Azure Service Bus throttle messages. Defaults: 500500

Message metadata

Azure Service Bus messages extend the Dapr message format with additional contextual metadata. Some metadata fields are set by Azure Service Bus itself (read-only) and others can be set by the client when publishing a message.

Sending a message with metadata

To set Azure Service Bus metadata when sending a message, set the query parameters on the HTTP request or the gRPC metadata as documented here.

  • metadata.MessageId
  • metadata.CorrelationId
  • metadata.SessionId
  • metadata.Label
  • metadata.ReplyTo
  • metadata.PartitionKey
  • metadata.To
  • metadata.ContentType
  • metadata.ScheduledEnqueueTimeUtc
  • metadata.ReplyToSessionId

NOTE: The metadata.MessageId property does not set the id property of the cloud event and should be treated in isolation.

Receiving a message with metadata

When Dapr calls your application, it will attach Azure Service Bus message metadata to the request using either HTTP headers or gRPC metadata. In addition to the settable metadata listed above, you can also access the following read-only message metadata.

  • metadata.DeliveryCount
  • metadata.LockedUntilUtc
  • metadata.LockToken
  • metadata.EnqueuedTimeUtc
  • metadata.SequenceNumber

To find out more details on the purpose of any of these metadata properties, please refer to the official Azure Service Bus documentation.

Create an Azure Service Bus

Follow the instructions here on setting up Azure Service Bus Topics.

Last modified February 18, 2022: Update setup-jetstream.md (#2200) (428d8c2)