---
title: Azure Service Bus actions
source: https://docs.newrelic.com/docs/workflow-automation/setup-and-configure/actions-catalog/azure/azure-service-bus
---

The Azure Service Bus actions let you send and receive messages from Azure Service Bus queues directly from your workflows. All actions authenticate using an Azure AD service principal (Entra app registration) and communicate with the Service Bus data plane.

The below actions follow two usage patterns:

-   **Send**: Use `sendMessage` to publish a message to a queue.
-   **Peek-lock lifecycle**: Use `peekLockMessage` to read and lock a message without removing it, then either `completeMessage` (processing succeeded — delete it) or `unlockMessage` (processing abandoned — return it to the queue). Use `renewLock` to extend the lock during long-running steps. For a simpler, destructive alternative, use `receiveAndDeleteMessage` to receive and immediately delete a message in one step.

## Prerequisites

-   An Azure Service Bus namespace and at least one queue.
-   An Entra (Azure AD) app registration (service principal). See [register an Azure app](https://learn.microsoft.com/en-us/azure/azure-monitor/logs/api/register-app-for-token).
-   Assign the appropriate built-in role on the namespace or queue:
    -   **Azure Service Bus Data Sender** — required for `sendMessage`.
    -   **Azure Service Bus Data Receiver** (or **Data Owner**) — required for `receiveAndDeleteMessage`, `peekLockMessage`, `renewLock`, `completeMessage`, and `unlockMessage`.
-   Store `clientId`, `clientSecret`, and `tenantId` as secrets in the New Relic Secrets Service and reference them using `${{ :secrets:<keyName> }}`.

## Send a message [#send-message]

**Action identifier:** `azure.serviceBus.sendMessage`

Sends a message to an Azure Service Bus queue.

### Inputs

| Input              | Type   | Description                                                                                                                                                                                                                                                                                          |
| ------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `clientId`         | String | **Required.** Entra service-principal client ID. Must be passed as a secret.                                                                                                                                                                                                                         |
| `clientSecret`     | String | **Required.** Entra service-principal client secret. Must be passed as a secret.                                                                                                                                                                                                                     |
| `tenantId`         | String | **Required.** Entra tenant ID. Must be passed as a secret.                                                                                                                                                                                                                                           |
| `namespace`        | String | **Required.** Service Bus namespace name, without the `.servicebus.windows.net` suffix. For example, `my-namespace`.                                                                                                                                                                                 |
| `queueName`        | String | **Required.** Name of the queue to send the message to. For example, `my-queue`.                                                                                                                                                                                                                     |
| `body`             | String | **Required.** Message body to send (max 256 KB). For example, `{"orderId": "12345", "status": "created"}`.                                                                                                                                                                                           |
| `contentType`      | String | **Required.** Content type of the message body, sent as the `Content-Type` header. Set explicitly on every call so consumers can correctly interpret the message body. For example, `application/json` or `text/plain`.                                                                              |
| `brokerProperties` | Map    | **Optional.** Broker metadata for the message. Accepted keys: `Label` (String), `TimeToLive` (Int, seconds), `CorrelationId` (String), `MessageId` (String), `ReplyTo` (String). The executor serializes this map to a JSON-encoded `BrokerProperties` header — you do not need to pre-serialize it. |
| `selectors`        | List   | **Optional.** JQ selectors to extract specific fields from the action output. For example, `[{"name": "statusCode", "expression": ".response.statusCode"}]`.                                                                                                                                         |

### Outputs

| Output         | Type    | Description                                                                                                                                                                                                                  |
| -------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `success`      | Boolean | `true` on HTTP 201 (message accepted), `false` on error.                                                                                                                                                                     |
| `response`     | Object  | Present when `success` is `true`; `null` on error. Contains `statusCode` (Int). For more information, see the [Send Message to Queue REST API](https://learn.microsoft.com/en-us/rest/api/servicebus/send-message-to-queue). |
| `errorMessage` | String  | Error message if the send failed. `response` is `null` in that case.                                                                                                                                                         |

### Example

```yaml
name: sendOrderCreatedMessage
description: Send a message to a Service Bus queue
steps:
  - name: sendMessage
    type: action
    action: azure.serviceBus.sendMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      queueName: my-queue
      body: '{"orderId": "12345", "status": "created"}'
      contentType: application/json
      brokerProperties:
        Label: order-created
        TimeToLive: 300
      selectors:
        - name: statusCode
          expression: ".response.statusCode"
    next: end
```

## Receive and delete a message [#receive-and-delete-message]

**Action identifier:** `azure.serviceBus.receiveAndDeleteMessage`

Receives a message from an Azure Service Bus queue and permanently removes it in a single, destructive operation.

> #### ⚠️ IMPORTANT
>
> Permanently deletes the message on receipt. If the workflow fails after this step, the message cannot be recovered. Use [`azure.serviceBus.peekLockMessage`](#peek-lock-message) instead when the processing step might fail and you need the ability to retry.

### Inputs

| Input            | Type    | Description                                                                                                                                                                   |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `clientId`       | String  | **Required.** Entra service-principal client ID. Must be passed as a secret.                                                                                                  |
| `clientSecret`   | String  | **Required.** Entra service-principal client secret. Must be passed as a secret.                                                                                              |
| `tenantId`       | String  | **Required.** Entra tenant ID. Must be passed as a secret.                                                                                                                    |
| `namespace`      | String  | **Required.** Service Bus namespace name, without the `.servicebus.windows.net` suffix.                                                                                       |
| `queueName`      | String  | **Required.** Name of the queue to receive from.                                                                                                                              |
| `timeoutSeconds` | Integer | **Optional.** How long to wait for a message before returning empty (1–55 seconds). The 55-second ceiling is a New Relic platform limit, not an Azure constraint. Default: 5. |
| `selectors`      | List    | **Optional.** JQ selectors to extract specific fields from the action output. For example, `[{"name": "body", "expression": ".response.body"}]`.                              |

### Outputs

| Output         | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `success`      | Boolean | `true` for both a message found (HTTP 200) and an empty queue (HTTP 204). Check `messageFound` to distinguish between the two.                                                                                                                                                                                                                                                                                           |
| `messageFound` | Boolean | Top-level output (not inside `response`). `true` if a message was returned; `false` if the queue was empty (HTTP 204). An empty queue is not an error.                                                                                                                                                                                                                                                                   |
| `response`     | Object  | Present when `success` is `true`; `null` on error. Contains `statusCode` (Int), `body` (String, the message body), and `brokerProperties` (Map, including fields such as `MessageId`, `SequenceNumber`, `DeliveryCount`, and `EnqueuedTimeUtc`). For more information, see the [Receive and Delete Message REST API](https://learn.microsoft.com/en-us/rest/api/servicebus/receive-and-delete-message-destructive-read). |
| `errorMessage` | String  | Error message if the receive failed. `response` is `null` in that case.                                                                                                                                                                                                                                                                                                                                                  |

### Example

```yaml
name: drainQueueMessage
description: Receive and permanently delete the next message from a queue
steps:
  - name: receiveAndDeleteMessage
    type: action
    action: azure.serviceBus.receiveAndDeleteMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      queueName: my-queue
      timeoutSeconds: 30
      selectors:
        - name: messageFound
          expression: ".messageFound"
        - name: body
          expression: ".response.body"
    next: end
```

## Peek-lock a message [#peek-lock-message]

**Action identifier:** `azure.serviceBus.peekLockMessage`

Reads a message from an Azure Service Bus queue without removing it, and temporarily locks it so other consumers cannot see it while it is being processed. Returns a `location` value that you must pass to `completeMessage`, `unlockMessage`, or `renewLock` in subsequent steps.

> #### ⚠️ IMPORTANT
>
> `location` is a top-level output — reference it as `.steps.<stepName>.outputs.location`, not `.steps.<stepName>.outputs.response.location`. Reuse this same value in every subsequent `renewLock`, `completeMessage`, or `unlockMessage` step — `renewLock` does not echo `location` back as an output.

### Inputs

| Input            | Type    | Description                                                                                                                                                                   |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `clientId`       | String  | **Required.** Entra service-principal client ID. Must be passed as a secret.                                                                                                  |
| `clientSecret`   | String  | **Required.** Entra service-principal client secret. Must be passed as a secret.                                                                                              |
| `tenantId`       | String  | **Required.** Entra tenant ID. Must be passed as a secret.                                                                                                                    |
| `namespace`      | String  | **Required.** Service Bus namespace name, without the `.servicebus.windows.net` suffix.                                                                                       |
| `queueName`      | String  | **Required.** Name of the queue to peek-lock from.                                                                                                                            |
| `timeoutSeconds` | Integer | **Optional.** How long to wait for a message before returning empty (1–55 seconds). The 55-second ceiling is a New Relic platform limit, not an Azure constraint. Default: 5. |
| `selectors`      | List    | **Optional.** JQ selectors to extract specific fields from the action output. For example, `[{"name": "location", "expression": ".location"}]`.                               |

### Outputs

| Output         | Type    | Description                                                                                                                                                                                                                                                                                                                                            |
| -------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `success`      | Boolean | `true` for both a message found (HTTP 201) and an empty queue (HTTP 204). Check `messageFound` to distinguish between the two.                                                                                                                                                                                                                         |
| `messageFound` | Boolean | Top-level output (not inside `response`). `true` if a message was returned and locked; `false` if the queue was empty (HTTP 204). An empty queue is not an error.                                                                                                                                                                                      |
| `location`     | String  | Top-level output (not inside `response`). The Service Bus `Location` header value identifying the locked message. Pass this value unchanged to `completeMessage`, `unlockMessage`, or `renewLock`. Present only when a message was found.                                                                                                              |
| `response`     | Object  | Present when `success` is `true`; `null` on error. Contains `statusCode` (Int), `body` (String, the message body), and `brokerProperties` (Map, including `LockToken` and `LockedUntilUtc`). For more information, see the [Peek-Lock Message REST API](https://learn.microsoft.com/en-us/rest/api/servicebus/peek-lock-message-non-destructive-read). |
| `errorMessage` | String  | Error message if the peek-lock failed. `response` is `null` in that case.                                                                                                                                                                                                                                                                              |

### Example

```yaml
name: peekLockAndComplete
description: Peek-lock a message then mark it as processed
steps:
  - name: peekLockMessage
    type: action
    action: azure.serviceBus.peekLockMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      queueName: my-queue
      timeoutSeconds: 30
      selectors:
        - name: messageFound
          expression: ".messageFound"
        - name: location
          expression: ".location"
        - name: body
          expression: ".response.body"
  - name: completeMessage
    type: action
    action: azure.serviceBus.completeMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      location: ${{ .steps.peekLockMessage.outputs.location }}
    next: end
```

## Renew a message lock [#renew-lock]

**Action identifier:** `azure.serviceBus.renewLock`

Extends the lock duration on a peek-locked Azure Service Bus message, preventing the lock from expiring while a long-running workflow step is still processing it.

> #### ⚠️ IMPORTANT
>
> Does not return a `location` output. Azure's renew-lock response has no `Location` header. Continue referencing the original `peekLockMessage.outputs.location` value in every subsequent `renewLock`, `completeMessage`, and `unlockMessage` step — do not read `location` from a prior `renewLock` output. Returns HTTP 404 if called after the lock has already expired.

### Inputs

| Input          | Type   | Description                                                                                                                       |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `clientId`     | String | **Required.** Entra service-principal client ID. Must be passed as a secret.                                                      |
| `clientSecret` | String | **Required.** Entra service-principal client secret. Must be passed as a secret.                                                  |
| `tenantId`     | String | **Required.** Entra tenant ID. Must be passed as a secret.                                                                        |
| `namespace`    | String | **Required.** Service Bus namespace name, without the `.servicebus.windows.net` suffix.                                           |
| `location`     | String | **Required.** The `location` output from a prior `peekLockMessage` step. Use it unchanged — do not construct this value manually. |
| `selectors`    | List   | **Optional.** JQ selectors to extract specific fields from the action output.                                                     |

### Outputs

| Output         | Type    | Description                                                                                                                                                                                                                                                 |
| -------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `success`      | Boolean | `true` on HTTP 200 (lock renewed), `false` on error. HTTP 404 (lock expired) returns `success: false` with `errorMessage` set.                                                                                                                              |
| `response`     | Object  | Present only when `success` is `true`; `null` on error. Contains `statusCode` (always 200 when present). For more information, see the [Renew Lock for a Message REST API](https://learn.microsoft.com/en-us/rest/api/servicebus/renew-lock-for-a-message). |
| `errorMessage` | String  | Error message if the renew failed, for example because the lock already expired (HTTP 404). `response` is `null` in that case.                                                                                                                              |

### Example

```yaml
name: renewLockDuringProcessing
description: Peek-lock a message, wait, renew the lock, then complete it
steps:
  - name: peekLockMessage
    type: action
    action: azure.serviceBus.peekLockMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      queueName: my-queue
      timeoutSeconds: 30
      selectors:
        - name: location
          expression: ".location"
  - name: processMessage
    type: wait
    seconds: 15
  - name: renewLock
    type: action
    action: azure.serviceBus.renewLock
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      location: ${{ .steps.peekLockMessage.outputs.location }}
  - name: completeMessage
    type: action
    action: azure.serviceBus.completeMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      location: ${{ .steps.peekLockMessage.outputs.location }}
    next: end
```

## Complete a message [#complete-message]

**Action identifier:** `azure.serviceBus.completeMessage`

Marks a peek-locked Azure Service Bus message as successfully processed, permanently deleting it from the queue. This is the terminal "success" step of the peek-lock pattern.

### Inputs

| Input          | Type   | Description                                                                                                                       |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `clientId`     | String | **Required.** Entra service-principal client ID. Must be passed as a secret.                                                      |
| `clientSecret` | String | **Required.** Entra service-principal client secret. Must be passed as a secret.                                                  |
| `tenantId`     | String | **Required.** Entra tenant ID. Must be passed as a secret.                                                                        |
| `namespace`    | String | **Required.** Service Bus namespace name, without the `.servicebus.windows.net` suffix.                                           |
| `location`     | String | **Required.** The `location` output from a prior `peekLockMessage` step. Use it unchanged — do not construct this value manually. |
| `selectors`    | List   | **Optional.** JQ selectors to extract specific fields from the action output.                                                     |

### Outputs

| Output         | Type    | Description                                                                                                                                                                                                                             |
| -------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `success`      | Boolean | `true` on HTTP 200 (message deleted), `false` on error. HTTP 404 (lock expired or message not found) returns `success: false` with `errorMessage` set.                                                                                  |
| `response`     | Object  | Present only when `success` is `true`; `null` on error. Contains `statusCode` (always 200 when present). For more information, see the [Delete Message REST API](https://learn.microsoft.com/en-us/rest/api/servicebus/delete-message). |
| `errorMessage` | String  | Error message if the complete operation failed, for example because the lock expired (HTTP 404). `response` is `null` in that case.                                                                                                     |

### Example

```yaml
name: peekLockAndComplete
description: Peek-lock a message and mark it as successfully processed
steps:
  - name: peekLockMessage
    type: action
    action: azure.serviceBus.peekLockMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      queueName: my-queue
      timeoutSeconds: 30
      selectors:
        - name: location
          expression: ".location"
  - name: completeMessage
    type: action
    action: azure.serviceBus.completeMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      location: ${{ .steps.peekLockMessage.outputs.location }}
    next: end
```

## Unlock a message [#unlock-message]

**Action identifier:** `azure.serviceBus.unlockMessage`

Releases the lock on a peek-locked Azure Service Bus message, making it immediately available again for other consumers. This is the terminal "abandon" step of the peek-lock pattern — use it when the workflow determines it cannot or should not finish processing the message.

### Inputs

| Input          | Type   | Description                                                                                                                       |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `clientId`     | String | **Required.** Entra service-principal client ID. Must be passed as a secret.                                                      |
| `clientSecret` | String | **Required.** Entra service-principal client secret. Must be passed as a secret.                                                  |
| `tenantId`     | String | **Required.** Entra tenant ID. Must be passed as a secret.                                                                        |
| `namespace`    | String | **Required.** Service Bus namespace name, without the `.servicebus.windows.net` suffix.                                           |
| `location`     | String | **Required.** The `location` output from a prior `peekLockMessage` step. Use it unchanged — do not construct this value manually. |
| `selectors`    | List   | **Optional.** JQ selectors to extract specific fields from the action output.                                                     |

### Outputs

| Output         | Type    | Description                                                                                                                                                                                                                             |
| -------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `success`      | Boolean | `true` on HTTP 200 (lock released), `false` on error. HTTP 404 (lock expired or message not found) returns `success: false` with `errorMessage` set.                                                                                    |
| `response`     | Object  | Present only when `success` is `true`; `null` on error. Contains `statusCode` (always 200 when present). For more information, see the [Unlock Message REST API](https://learn.microsoft.com/en-us/rest/api/servicebus/unlock-message). |
| `errorMessage` | String  | Error message if the unlock failed, for example because the lock expired (HTTP 404). `response` is `null` in that case.                                                                                                                 |

### Example

```yaml
name: peekLockAndAbandon
description: Peek-lock a message then release it back to the queue unprocessed
steps:
  - name: peekLockMessage
    type: action
    action: azure.serviceBus.peekLockMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      queueName: my-queue
      timeoutSeconds: 30
      selectors:
        - name: location
          expression: ".location"
  - name: unlockMessage
    type: action
    action: azure.serviceBus.unlockMessage
    version: '1'
    inputs:
      clientId: ${{ :secrets:azure-client-id }}
      clientSecret: ${{ :secrets:azure-client-secret }}
      tenantId: ${{ :secrets:azure-client-tenant }}
      namespace: my-namespace
      location: ${{ .steps.peekLockMessage.outputs.location }}
    next: end
```
