# Service Bus

> Send messages to Service Bus queues and topics, and check the messages your services send there.

Source: https://axx.nimbusxr.us/references/steps/azure-servicebus/

Send messages to Service Bus queues and topics, and check the messages your services send there.

Register the namespace with `the {word} service bus namespace with the following properties:` (the first namespace registered is the default), set up as the Azure SDK is set up for the real service:

| Property | |
| --- | --- |
| `connection string` | the namespace's connection string, e.g. `${env:SERVICEBUS_CONNECTION_STRING}`, or a local emulator's (`UseDevelopmentEmulator=true`) |
| `namespace` | the fully qualified namespace (`<name>.servicebus.windows.net`), signed in with the Azure default credential chain |
| `management endpoint` | where the namespace's management API is when it is not the namespace's own host, as with local emulators |

Steps name a **queue** or a **topic**: `the customs-filings service bus queue`, `the customs-events service bus topic`. Messages carry application properties (`with the following properties:`, and `property <name>` rows in checks).

**Checking a queue receives from it**: Axx completes each message it receives, as any consumer would, so check the queues your services **write** to. **Checking a topic** takes nothing from anyone: for the topics a run checks, Axx creates a subscription of its own (`axx-<run>`, through the management API, so it needs the Manage right) once the apps are up, and deletes it when the run ends. A check only looks at the messages received since its scenario started.

## `azure-servicebus.namespace`

```gherkin
Given the {word} service bus namespace with the following properties:
  | ... | ... |
```

Register the Service Bus namespace the steps talk to: `connection string`, or `namespace` with the Azure default credential chain; `management endpoint` for an emulator whose management API is elsewhere.

**Parameters:** `{word}` (one word, no spaces)

**Example:**

```gherkin
Given the customs service bus namespace with the following properties:
```

_Since 0.1.0._

## `azure-servicebus.send`

```gherkin
When a message is sent to the {word} service bus queue:/topic:
  """
  ...
  """
```

Send a message whose body is the doc string to a service bus queue/topic.

**Parameters:** `{word}` (one word, no spaces)

**Example:**

```gherkin
When a message is sent to the customs-filings service bus queue/topic:
```

_Since 0.1.0._

## `azure-servicebus.send.file`

```gherkin
When the {filepath} message is sent to the {word} service bus queue/topic[[ with the following properties:]]
```

Send a message whose body is the file (resolved against `resources`) to a service bus queue/topic, with the properties of the table (`name | value`).

**Variants** (optional parts in `[[...]]` above):

- `the {filepath} message is sent to the {word} service bus queue/topic`
- `the {filepath} message is sent to the {word} service bus queue/topic with the following properties:`

**Parameters:** `{filepath}` (A file of the project, without whitespace: a path relative to the `resources` directories or to the directory of axx.yaml, or an absolute path. Editors link it to the file), `{word}` (one word, no spaces)

**Example:**

```gherkin
When the messages/shipment-delivered.json message is sent to the customs-filings service bus queue/topic
When the messages/shipment-delivered.json message is sent to the customs-filings service bus queue/topic with the following properties:
```

_Since 0.1.0._

## `azure-servicebus.received`

```gherkin
Then [[within {duration} ]]the {word} service bus queue/topic has a message where:
  | ... | ... |
```

Wait (10s, or the given time) until the service bus queue/topic has a message, received since the scenario started, that meets every row: `path | value` on the JSON body (a field name, a dotted path or a JSONPath, compared as text; `null` for null and `undefined` for absent), or `property <name> | value` on a property sent with it. Axx completes the messages of a queue it checks, and subscribes to a topic for the run.

**Variants** (optional parts in `[[...]]` above):

- `the {word} service bus queue/topic has a message where:`
- `within {duration} the {word} service bus queue/topic has a message where:`

**Parameters:** `{duration}` (A duration in seconds or minutes, e.g. `5s` or `2m`), `{word}` (one word, no spaces)

**Example:**

```gherkin
Then within 30s the customs-filings service bus queue/topic has a message where:
```

_Since 0.1.0._
