Azure Service Bus Queues binding spec

Detailed documentation on the Azure Service Bus Queues binding component

Component format

To setup Azure Service Bus Queues binding create a component of type bindings.azure.servicebusqueues. See this guide on how to create and apply a binding configuration.

Connection String Authentication

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. spec:
  6. type: bindings.azure.servicebusqueues
  7. version: v1
  8. metadata:
  9. - name: connectionString # Required when not using Azure Authentication.
  10. value: "Endpoint=sb://{ServiceBusNamespace}.servicebus.windows.net/;SharedAccessKeyName={PolicyName};SharedAccessKey={Key};EntityPath={ServiceBus}"
  11. - name: queueName
  12. value: "queue1"
  13. # - name: timeoutInSec # Optional
  14. # value: "60"
  15. # - name: handlerTimeoutInSec # Optional
  16. # value: "60"
  17. # - name: disableEntityManagement # Optional
  18. # value: "false"
  19. # - name: maxDeliveryCount # Optional
  20. # value: "3"
  21. # - name: lockDurationInSec # Optional
  22. # value: "60"
  23. # - name: lockRenewalInSec # Optional
  24. # value: "20"
  25. # - name: maxActiveMessages # Optional
  26. # value: "10000"
  27. # - name: maxConcurrentHandlers # Optional
  28. # value: "10"
  29. # - name: defaultMessageTimeToLiveInSec # Optional
  30. # value: "10"
  31. # - name: autoDeleteOnIdleInSec # Optional
  32. # value: "3600"
  33. # - name: minConnectionRecoveryInSec # Optional
  34. # value: "2"
  35. # - name: maxConnectionRecoveryInSec # Optional
  36. # value: "300"
  37. # - name: maxRetriableErrorsPerSec # Optional
  38. # value: "10"
  39. # - name: publishMaxRetries # Optional
  40. # value: "5"
  41. # - name: publishInitialRetryIntervalInMs # Optional
  42. # value: "500"
  43. # - name: direction
  44. # value: "input, output"

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

FieldRequiredBinding supportDetailsExample
connectionStringYInput/OutputThe Service Bus connection string. Required unless using Microsoft Entra ID authentication.“Endpoint=sb://**
queueNameYInput/OutputThe Service Bus queue name. Queue names are case-insensitive and will always be forced to lowercase.“queuename”
timeoutInSecNInput/OutputTimeout for all invocations to the Azure Service Bus endpoint, in seconds. Note that this option impacts network calls and it’s unrelated to the TTL applies to messages. Default: “60”“60”
namespaceNameNInput/OutputParameter to set the address of the Service Bus namespace, as a fully-qualified domain name. Required if using Microsoft Entra ID authentication.“namespace.servicebus.windows.net”
disableEntityManagementNInput/OutputWhen set to true, queues and subscriptions do not get created automatically. Default: “false”“true”, “false”
lockDurationInSecNInput/OutputDefines the length in seconds that a message will be locked for before expiring. Used during subscription creation only. Default set by server.“30”
autoDeleteOnIdleInSecNInput/OutputTime in seconds to wait before auto deleting idle subscriptions. Used during subscription creation only. Default: “0” (disabled)“3600”
defaultMessageTimeToLiveInSecNInput/OutputDefault message time to live, in seconds. Used during subscription creation only.“10”
maxDeliveryCountNInput/OutputDefines the number of attempts the server will make to deliver a message. Used during subscription creation only. Default set by server.“10”
minConnectionRecoveryInSecNInput/OutputMinimum interval (in seconds) to wait before attempting to reconnect to Azure Service Bus in case of a connection failure. Default: “2”“5”
maxConnectionRecoveryInSecNInput/OutputMaximum interval (in seconds) to wait before attempting to reconnect to Azure Service Bus in case of a connection failure. After each attempt, the component waits a random number of seconds, increasing every time, between the minimum and the maximum. Default: “300” (5 minutes)“600”
maxActiveMessagesNDefines the maximum number of messages to be processing or in the buffer at once. This should be at least as big as the maximum concurrent handlers. Default: “1”“1”
handlerTimeoutInSecNInputTimeout for invoking the app’s handler. Default: “0” (no timeout)“30”
minConnectionRecoveryInSecNInputMinimum interval (in seconds) to wait before attempting to reconnect to Azure Service Bus in case of a connection failure. Default: “2”“5”
maxConnectionRecoveryInSecNInputMaximum interval (in seconds) to wait before attempting to reconnect to Azure Service Bus in case of a connection failure. After each attempt, the binding waits a random number of seconds, increasing every time, between the minimum and the maximum. Default: “300” (5 minutes)“600”
lockRenewalInSecNInputDefines the frequency at which buffered message locks will be renewed. Default: “20”.“20”
maxActiveMessagesNInputDefines the maximum number of messages to be processing or in the buffer at once. This should be at least as big as the maximum concurrent handlers. Default: “1”“2000”
maxConcurrentHandlersNInputDefines the maximum number of concurrent message handlers; set to 0 for unlimited. Default: “1”“10”
maxRetriableErrorsPerSecNInputMaximum number of retriable errors that are processed per second. If a message fails to be processed with a retriable error, the component adds a delay before it starts processing another message, to avoid immediately re-processing messages that have failed. Default: “10”“10”
publishMaxRetriesNOutputThe max number of retries for when Azure Service Bus responds with “too busy” in order to throttle messages. Defaults: “5”“5”
publishInitialRetryIntervalInMsNOutputTime in milliseconds for the initial exponential backoff when Azure Service Bus throttle messages. Defaults: “500”“500”
directionNInput/OutputThe direction of the binding“input”, “output”, “input, output”

Microsoft Entra ID authentication

The Azure Service Bus Queues binding component supports authentication using all Microsoft Entra ID mechanisms, including Managed Identities. For further information and the relevant component metadata fields to provide depending on the choice of Microsoft Entra ID authentication mechanism, see the docs for authenticating to Azure.

Example Configuration

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. spec:
  6. type: bindings.azure.servicebusqueues
  7. version: v1
  8. metadata:
  9. - name: azureTenantId
  10. value: "***"
  11. - name: azureClientId
  12. value: "***"
  13. - name: azureClientSecret
  14. value: "***"
  15. - name: namespaceName
  16. # Required when using Azure Authentication.
  17. # Must be a fully-qualified domain name
  18. value: "servicebusnamespace.servicebus.windows.net"
  19. - name: queueName
  20. value: queue1
  21. - name: ttlInSeconds
  22. value: 60

Binding support

This component supports both input and output binding interfaces.

This component supports output binding with the following operations:

  • create: publishes a message to the specified queue

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 through Invoke binding call with create operation.

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 returned by Dapr and should be treated in isolation.
  • The metadata.ScheduledEnqueueTimeUtc property supports the RFC1123 and RFC3339 timestamp formats.

Receiving a message with metadata

When Dapr calls your application, it attaches 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.

Note

All times are populated by the server and are not adjusted for clock skews.

Specifying a TTL per message

Time to live can be defined on a per-queue level (as illustrated above) or at the message level. The value defined at message level overwrites any value set at the queue level.

To set time to live at message level use the metadata section in the request body during the binding invocation: the field name is ttlInSeconds.

  1. curl -X POST http://localhost:3500/v1.0/bindings/myServiceBusQueue \
  2. -H "Content-Type: application/json" \
  3. -d '{
  4. "data": {
  5. "message": "Hi"
  6. },
  7. "metadata": {
  8. "ttlInSeconds": "60"
  9. },
  10. "operation": "create"
  11. }'

Schedule a message

A message can be scheduled for delayed processing.

To schedule a message, use the metadata section in the request body during the binding invocation: the field name is ScheduledEnqueueTimeUtc.

The supported timestamp formats are RFC1123 and RFC3339.

  1. curl -X POST http://localhost:3500/v1.0/bindings/myServiceBusQueue \
  2. -H "Content-Type: application/json" \
  3. -d '{
  4. "data": {
  5. "message": "Hi"
  6. },
  7. "metadata": {
  8. "ScheduledEnqueueTimeUtc": "Tue, 02 Jan 2024 15:04:05 GMT"
  9. },
  10. "operation": "create"
  11. }'

Last modified March 21, 2024: Merge pull request #4082 from newbe36524/v1.13 (f4b0938)