|
1 | 1 | # Messenger Azure Service Bus Bundle |
2 | 2 | A **Symfony 4 / 5 / 6** bundle providing a **Symfony Messenger** *transport* for **Azure Service Bus** using the *Azure REST API*. |
3 | 3 |
|
4 | | ->This is a work in progress bundle. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +[](//packagist.org/packages/aymdev/messenger-azure-bundle) |
| 8 | +[](//packagist.org/packages/aymdev/messenger-azure-bundle) |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +You only need to install the bundle using **Composer**: |
| 13 | +```shell |
| 14 | +composer require aymdev/messenger-azure-bundle |
| 15 | +``` |
| 16 | +As it uses [Symfony HttpClient](https://symfony.com/doc/current/http_client.html), |
| 17 | +you will need to install a [PSR-18 client](https://symfony.com/doc/current/http_client.html#psr-18-and-psr-17). |
| 18 | +Example: |
| 19 | +```shell |
| 20 | +composer require nyholm/psr7 |
| 21 | +``` |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +### Transport DSN |
| 26 | + |
| 27 | +Your DSN must respect the following format to build the authentication header for a specific *namespace*: |
| 28 | +``` |
| 29 | +azure://KEY_NAME:KEY_VALUE@NAMESPACE |
| 30 | +``` |
| 31 | +>Where `KEY_NAME` is your **shared access key name**, `KEY_VALUE` is your **shared access key** and `NAMESPACE` is your |
| 32 | +>*Azure Service Bus* **namespace**. |
| 33 | +
|
| 34 | +### Transport options |
| 35 | + |
| 36 | +Detailed list of transport options: |
| 37 | + |
| 38 | +| Option name | Description | Required | Default value | |
| 39 | +| ------------- | ------------- | ----: | ----: | |
| 40 | +| `entity_path` | The **topic** or **queue** name. | Yes | | |
| 41 | +| `subscription` | The subcription name to consume messages from a **topic**. | Only for *topic consumer transports* | | |
| 42 | +| `token_expiry` | [SAS token](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-sas#generate-a-shared-access-signature-token) validity duration in seconds. | | `3600` | |
| 43 | +| `receive_mode` | Set to `peek-lock` to perform a [non destructive read](https://docs.microsoft.com/en-us/rest/api/servicebus/peek-lock-message-non-destructive-read) or to `receive-and-delete` to perform a [destructive-read](https://docs.microsoft.com/en-us/rest/api/servicebus/receive-and-delete-message-destructive-read) | | `peek-lock` | |
| 44 | + |
| 45 | +Example `config/packages/messenger.yaml`: |
| 46 | +```yaml |
| 47 | +framework: |
| 48 | + messenger: |
| 49 | + transports: |
| 50 | + azure_transport: |
| 51 | + dsn: '%env(AZURE_SERVICE_BUS_DSN)%' |
| 52 | + serializer: 'App\Messenger\YourAzureSerializer' |
| 53 | + options: |
| 54 | + entity_path: 'your-topic' |
| 55 | + subscription: 'subscription-name' |
| 56 | + token_expiry: 60 |
| 57 | + receive_mode: 'receive-and-delete' |
| 58 | +``` |
| 59 | +
|
| 60 | +## Stamps |
| 61 | +
|
| 62 | +This transport provides 2 stamps: |
| 63 | +
|
| 64 | +### AzureReceivedStamp |
| 65 | +
|
| 66 | +The `AymDev\MessengerAzureBundle\Messenger\Stamp\AzureReceivedStamp` stamp holds the original message body and an optional deletion URL. |
| 67 | + |
| 68 | +### AzureBrokerPropertiesStamp |
| 69 | + |
| 70 | +The `AymDev\MessengerAzureBundle\Messenger\Stamp\AzureBrokerPropertiesStamp` stamp is used for the [message properties](https://docs.microsoft.com/en-us/rest/api/servicebus/message-headers-and-properties). |
| 71 | +It is automatically decoded when consuming a message and is encoded when producing a message if added to the *envelope*. |
| 72 | + |
| 73 | +## Serialization |
| 74 | + |
| 75 | +There is no serializer provided, but here is the expected array structure of an encoded envelope: |
| 76 | + |
| 77 | + - `body`: your plain text message |
| 78 | + - `headers`: optional HTTP headers (either received from *Azure Service Bus* response or to send to the REST API) |
0 commit comments