aymdev / messenger-azure-bundle
Symfony Messenger 为 Azure Service Bus 提供的 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.
安装
您只需使用 Composer 安装此 bundle
composer require aymdev/messenger-azure-bundle
因为它使用 Symfony HttpClient,您需要安装一个 PSR-18 客户端。示例
composer require nyholm/psr7
配置
传输 DSN
您的 DSN 必须遵循以下格式以构建特定 namespace 的认证头
azure://KEY_NAME:KEY_VALUE@NAMESPACE
其中
KEY_NAME
是您的 shared access key name,KEY_VALUE
是您的 shared access key,NAMESPACE
是您的 Azure Service Bus namespace。 重要提示:键可以包含特殊字符,这可能会破坏 URL 解析。请确保对它们进行 URL 编码。
传输选项
传输选项的详细列表
示例 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'
戳记
此传输提供了一些戳记
AzureMessageStamp
AymDev\MessengerAzureBundle\Messenger\Stamp\AzureMessageStamp
标记添加到发送和接收的消息中,并包含
- 主题或队列名称
- 原始发送/接收消息
- 来自主题的接收消息的订阅名称
- 在
peek-lock
接收模式下的接收消息的删除 URL
AzureBrokerPropertiesStamp
AymDev\MessengerAzureBundle\Messenger\Stamp\AzureBrokerPropertiesStamp
标记用于 消息属性。在消费消息时自动解码,在将消息添加到 envelope 时编码。
序列化
创建您的序列化器
没有提供序列化器,但以下是编码信封的预期数组结构
body
: 您的纯文本消息headers
: 可选 HTTP 头部(从 Azure Service Bus 响应接收或发送到 REST API)
记录解码错误
当序列化器在解码消息时抛出 Symfony\Component\Messenger\Exception\MessageDecodingFailedException
时,它将被转换为 AymDev\MessengerAzureBundle\Messenger\Exception\SerializerDecodingException
,该异常包含一个信封,其中包含空消息,但具有与成功解码的消息相同的戳记。
然后您可以通过 监听 console.error
Symfony 事件,获取解码失败时的话题/队列名称、原始消息等。