stables-q/messenger-enqueue-transport
Composer 安装命令:
composer require stables-q/messenger-enqueue-transport
包简介
Enqueue adapter for Symfony Messenger component
关键字:
README 文档
README
This Symfony Messenger transport allows you to use Enqueue to send and receive your messages from all the supported brokers.
Usage
- Install the transport
composer req sroze/messenger-enqueue-transport
- Configure the Enqueue bundle as you would normaly do (see Enqueue's Bundle documentation). If you are using the recipes, you should
just have to configure the environment variables to configure the
defaultEnqueue transport:
# .env # ... ###> enqueue/enqueue-bundle ### ENQUEUE_DSN=amqp://guest:guest@localhost:5672/%2f ###< enqueue/enqueue-bundle ###
- Configure Messenger's transport (that we will name
amqp) to use Enqueue'sdefaulttransport:
# config/packages/messenger.yaml framework: messenger: transports: amqp: enqueue://default
- Route the messages that have to go through the message queue:
# config/packages/framework.yaml framework: messenger: # ... routing: 'App\Message\MyMessage': amqp
- Consume!
bin/console messenger:consume amqp
Advanced usage
Configure the queue(s) and exchange(s)
In the transport DSN, you can add extra configuration. Here is the common reference DSN (note that the values are just for the example):
enqueue://default
?queue[name]=queue_name
&topic[name]=topic_name
&deliveryDelay=1800
&delayStrategy=Enqueue\AmqpTools\RabbitMqDelayPluginDelayStrategy
&timeToLive=3600
&receiveTimeout=1000
&priority=1
Setting Custom Configuration on your Message
Each Enqueue transport (e.g. amqp, redis, etc) has its own message object
that can normally be configured by calling setter methods (e.g.
$message->setDeliveryDelay(5000)). But in Messenger, you don't have access
to these objects directly. Instead, you can set them indirectly via
the TransportConfiguration stamp:
use Symfony\Component\Messenger\Envelope; use Enqueue\MessengerAdapter\EnvelopeItem\TransportConfiguration; // ... // create your message like normal $message = // ... $transportConfig = (new TransportConfiguration()) // commmon options have a convenient method ->setDeliveryDelay(5000) // other transport-specific options are set via metadata // example custom option for AmqpMessage // each "metadata" will map to a setter on your message // will result in setDeliveryMode(AmqpMessage::DELIVERY_MODE_PERSISTENT) // being called ->addMetadata('deliveryMode', AmqpMessage::DELIVERY_MODE_PERSISTENT) ; $bus->dispatch((new Envelope($message))->with($transportConfig));
Send a message on a specific topic
You can send a message on a specific topic using TransportConfiguration envelope item with your message:
use Symfony\Component\Messenger\Envelope; use Enqueue\MessengerAdapter\EnvelopeItem\TransportConfiguration; // ... $transportConfig = (new TransportConfiguration()) ->setTopic('specific-topic') ; $bus->dispatch((new Envelope($message))->with($transportConfig));
Use AMQP topic exchange
See https://www.rabbitmq.com/tutorials/tutorial-five-php.html
You can use specific topic and queue options to configure your AMQP exchange in topic mode and bind it:
enqueue://default
?queue[name]=queue_name
&queue[bindingKey]=foo.#
&topic[name]=topic_name
&topic[type]=topic
&deliveryDelay=1800
&delayStrategy=Enqueue\AmqpTools\RabbitMqDelayPluginDelayStrategy
&timeToLive=3600
&receiveTimeout=1000
&priority=1
Here is the way to send a message with a routing key matching this consumer:
$bus->dispatch((new Envelope($message))->with(new TransportConfiguration([ 'topic' => 'topic_name', 'metadata' => [ 'routingKey' => 'foo.bar' ] ])));
Configure custom Kafka message
Here is the way to send a message with with some custom options:
$this->bus->dispatch((new Envelope($message))->with(new TransportConfiguration([ 'topic' => 'test_topic_name', 'metadata' => [ 'key' => 'foo.bar', 'partition' => 0, 'timestamp' => (new \DateTimeImmutable())->getTimestamp(), 'messageId' => uniqid('kafka_', true), ] ])))
stables-q/messenger-enqueue-transport 适用场景与选型建议
stables-q/messenger-enqueue-transport 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 710 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「Messenger」 「enqueue」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stables-q/messenger-enqueue-transport 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stables-q/messenger-enqueue-transport 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stables-q/messenger-enqueue-transport 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Swiftmailer Spool using the Enqueue message queue
The bundle for easy using json-rpc api on your project
Enables the creation of cron-jobs tasks to be consumed by symfony/messenger
Messenger functionality for Laravel 5.2.
统计信息
- 总下载量: 710
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-09