happyr / simplebus-bundle
Happyr 如何使用 SimpleBus
0.1.2
2017-06-27 08:41 UTC
Requires
- php: ^7.0
- happyr/mq2php-bundle: ^0.2.4
- psr/log: ~1.0
- simple-bus/asynchronous: ^2.1
- simple-bus/asynchronous-bundle: ^2.3
- simple-bus/doctrine-orm-bridge: ^4.0
- simple-bus/jms-serializer-bundle-bridge: ^2.0.2
- simple-bus/rabbitmq-bundle-bridge: ^3.1
- simple-bus/symfony-bridge: ^4.1.5
Requires (Dev)
- nyholm/symfony-bundle-test: ^1.0.2
- phpunit/phpunit: ^5.7
- simple-bus/jms-serializer-bundle-bridge: ^2.0
- symfony/symfony: ^3.0
This package is auto-updated.
Last update: 2024-08-25 08:06:43 UTC
README
此包包含 Happyr 在 SimpleBus 安装中需要的所有额外功能。其目的不是100%可重用和灵活。您可以随意使用它并根据您的需求进行调整。
安装
composer require happyr/simplebus-bundle
class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new Happyr\SimpleBusBundle\HappyrSimpleBusBundle(), // <-- Make sure this is before the SimpleBusBrige bundles. new Happyr\Mq2phpBundle\HappyrMq2phpBundle(), new SimpleBus\SymfonyBridge\SimpleBusCommandBusBundle(), new SimpleBus\SymfonyBridge\SimpleBusEventBusBundle(), new SimpleBus\AsynchronousBundle\SimpleBusAsynchronousBundle(), new SimpleBus\RabbitMQBundleBridge\SimpleBusRabbitMQBundleBridgeBundle(), new SimpleBus\JMSSerializerBundleBridge\SimpleBusJMSSerializerBundleBridgeBundle(), new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(), new JMS\SerializerBundle\JMSSerializerBundle(), new SimpleBus\JMSSerializerBundleBridge\SimpleBusJMSSerializerBundleBridgeBundle(), ]; // ... } // ... }
# /app/config/happyr_simplebus.yml parameters: app.command_queue: 'commands' app.event_queue: 'events' simple_bus.command_bus.logging.level: info simple_bus.event_bus.logging.level: info happyr_mq2php: enabled: true secret_key: 'CHANGE_ME' command_queue: "%app.command_queue%" event_queue: "%app.event_queue%" message_headers: fastcgi_host: "%fastcgi_host%" fastcgi_port: "%fastcgi_port%" dispatch_path: "%mq2php_dispatch_path%" command_bus: logging: ~ event_bus: logging: ~ simple_bus_rabbit_mq_bundle_bridge: commands: # this producer service will be defined by OldSoundRabbitMqBundle, # its name is old_sound_rabbit_mq.%producer_name%_producer producer_service_id: old_sound_rabbit_mq.asynchronous_commands_producer events: # this producer service will be defined by OldSoundRabbitMqBundle, # its name is old_sound_rabbit_mq.%producer_name%_producer producer_service_id: old_sound_rabbit_mq.asynchronous_events_producer simple_bus_asynchronous: events: strategy: 'predefined' old_sound_rabbit_mq: connections: default: host: "%rabbitmq_host%" port: 5672 user: 'guest' password: 'guest' vhost: '/' lazy: false connection_timeout: 3 read_write_timeout: 3 # requires php-amqplib v2.4.1+ and PHP5.4+ keepalive: false # requires php-amqplib v2.4.1+ heartbeat: 0 producers: asynchronous_commands: connection: default exchange_options: { name: '%app.command_queue%', type: "x-delayed-message", arguments: {"x-delayed-type": ["S","direct"]} } queue_options: { name: "%app.command_queue%", durable: true } asynchronous_events: connection: default exchange_options: { name: '%app.event_queue%', type: "x-delayed-message", arguments: {"x-delayed-type": ["S","direct"]} } queue_options: { name: "%app.event_queue%", durable: true }
继续阅读 Mq2phpBundle。请确保安装 RabbitMQ 扩展 以支持延迟消息。
使用
在
src/App/Message
Command
CommandHandler
Event
EventSubscriber
创建您的消息,它们将被自动绑定并注册。当然,您也可以手动注册它们。
类 & 接口
请注意以下基本类。
BaseCommandHandler
BaseEventSubscriber
实现AutoRegisteredEventSubscriber
HandlesMessagesAsync
(用于异步处理程序/订阅者)DelayedMessage
(用于带延迟的异步消息)
直接发布者
如果您不想使用队列,您可以使用直接发布者。
happyr_simplebus:
use_direct_publisher: true