sroze / swarrot-bridge
Symfony Message 组件的 Swarrot 桥接器
dev-master / 1.0.x-dev
2017-10-08 12:41 UTC
Requires
- swarrot/swarrot-bundle: ^1.5@dev
This package is auto-updated.
Last update: 2024-08-29 04:54:17 UTC
README
此桥接器允许您使用设计精良的 Swarrot 库 消费和产生消息,以供各种消息代理使用。
用法
- 安装 Swarrot 桥接器
composer req sroze/swarrot-bridge:dev-master
- 在您的应用程序中配置 Swarrot 扩展。
# config/packages/swarrot.yaml swarrot: default_connection: rabbitmq connections: rabbitmq: host: 'localhost' port: 5672 login: 'guest' password: 'guest' vhost: '/' consumers: my_consumer: processor: app.message_processor middleware_stack: - configurator: swarrot.processor.signal_handler - configurator: swarrot.processor.max_messages extras: max_messages: 100 - configurator: swarrot.processor.doctrine_connection extras: doctrine_ping: true - configurator: swarrot.processor.doctrine_object_manager - configurator: swarrot.processor.exception_catcher - configurator: swarrot.processor.ack messages_types: my_publisher: connection: rabbitmq # use the default connection by default exchange: my_exchange
重要提示: Swarrot 不会自动为您创建交换、队列和绑定。您需要在 RabbitMq(或您使用的其他连接器)中手动配置这些。
- 注册生产者和处理器。
# config/services.yaml services: # ... app.message_producer: class: Sam\Symfony\Bridge\SwarrotMessage\SwarrotProducer arguments: - "@swarrot.publisher" - "@message.transport.default_encoder" - my_publisher app.message_processor: class: Sam\Symfony\Bridge\SwarrotMessage\SwarrotProcessor arguments: - "@message_bus" - "@message.transport.default_decoder"
请注意,处理器是 Swarrot 特有的。由于 Swarrot 的功能是消费消息,因此在此上下文中我们将不使用 Message 组件的命令,而是使用 Swarrot 的命令。我们在前面的文件配置中已配置 Swarrot 使用此处理器。
- 将您的消息路由到总线
# config/packages/framework.yaml message: routing: 'App\Message\MyMessage': app.message_producer
- 消费您的消息!
bin/console swarrot:consume:my_consumer queue_name_you_created