aymdev / messenger-azure-bundle
Symfony Messenger bundle for Azure Service Bus
Installs: 106 509
Dependents: 1
Suggesters: 0
Security: 0
Stars: 10
Watchers: 2
Forks: 7
Open Issues: 6
Type:symfony-bundle
Requires
- php: ^8.1
- ext-json: *
- symfony/dependency-injection: ^5.4|^6.4|^7.0
- symfony/http-client: ^5.4|^6.4|^7.0
- symfony/http-kernel: ^5.4|^6.4|^7.0
- symfony/messenger: ^5.4|^6.4|^7.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.1
- phpcompatibility/php-compatibility: ^9.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.4
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-strict-rules: ^1.1
- squizlabs/php_codesniffer: ^3.6
- symfony/phpunit-bridge: ^5.4|^6.4|^7.0
README
A PHP 8.1+ & Symfony 5 / 6 / 7 bundle providing a Symfony Messenger transport for Azure Service Bus using the Azure REST API.
Installation
You only need to install the bundle using Composer:
composer require aymdev/messenger-azure-bundle
As it uses Symfony HttpClient, you will need to install a PSR-18 client. Example:
composer require nyholm/psr7
Configuration
Transport DSN
Your DSN must respect the following format to build the authentication header for a specific namespace:
azure://KEY_NAME:KEY_VALUE@NAMESPACE
Where
KEY_NAME
is your shared access key name,KEY_VALUE
is your shared access key andNAMESPACE
is your Azure Service Bus namespace. Important note: the keys can contain special characters that could break the URL parsing. Be sure to URL encode them.
Transport options
Detailed list of transport options:
Example config/packages/messenger.yaml
:
framework: messenger: transports: azure_transport: dsn: '%env(AZURE_SERVICE_BUS_DSN)%' serializer: 'App\Messenger\YourAzureSerializer' options: entity_path: 'your-topic' subscription: 'subscription-name' token_expiry: 60 receive_mode: 'receive-and-delete'
Stamps
This transport provides a few stamps:
AzureMessageStamp
The AymDev\MessengerAzureBundle\Messenger\Stamp\AzureMessageStamp
stamp is added to sent and received messages and
contains:
- the topic or queue name
- the original sent/received message
- the subscription name for received messages from topics
- the delete URL for received messages in
peek-lock
receive mode
AzureBrokerPropertiesStamp
The AymDev\MessengerAzureBundle\Messenger\Stamp\AzureBrokerPropertiesStamp
stamp is used for the message properties.
It is automatically decoded when consuming a message and is encoded when producing a message if added to the envelope.
Serialization
Creating your serializers
There is no serializer provided, but here is the expected array structure of an encoded envelope:
body
: your plain text messageheaders
: optional HTTP headers (either received from Azure Service Bus response or to send to the REST API)
Logging decoding errors
When a serializer throws a Symfony\Component\Messenger\Exception\MessageDecodingFailedException
while decoding a message,
it will be converted to a AymDev\MessengerAzureBundle\Messenger\Exception\SerializerDecodingException
which contains an
envelope with an empty message but with the same stamps as a successfully decoded message.
You can then listen to the console.error
Symfony event and get
the topic/queue name where then decoding failure happened, the original message, etc.