b2pweb / bdf-queue-bundle
Symfony BdfQueueBundle
v1.4.0
2024-03-12 11:29 UTC
Requires
- php: ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
- b2pweb/bdf-queue: ~1.4
- symfony/config: ^6.0
- symfony/dependency-injection: ^6.0
- symfony/expression-language: ^6.0
- symfony/framework-bundle: ^6.0
Requires (Dev)
- b2pweb/bdf-prime-bundle: ~1.2
- friendsofphp/php-cs-fixer: ~3.0
- phpunit/phpunit: ~9.0
- symfony/console: ^6.0
- symfony/phpunit-bridge: ^6.0
- symfony/yaml: ^6.0
Conflicts
- doctrine/doctrine-bundle: >=2.9
- doctrine/instantiator: ~2.0
README
安装
1 下载包
使用composer下载此包的最新稳定版本
$ composer require b2pweb/bdf-queue-bundle
2 启用包
在项目的 config/bundles.php
文件中添加以下行:
<?php // config/bundles.php return [ // ... Bdf\QueueBundle\BdfQueueBundle::class => ['all' => true], // ... ];
3 设置环境
在.env
文件中添加你的dsn
BDF_QUEUE_CONNETION_URL=gearman://root@127.0.0.1?client-timeout=10
4 添加配置
在./config/packages/bdf_queue.yaml
中添加默认配置文件
bdf_queue: default_connection: 'gearman' default_serializer: 'bdf' connections: gearman: # A URL with connection information. # Any parameter value parsed from this string will override explicitly set parameters. # Format: {driver}+{vendor}://{user}:{password}@{host}:{port}/{queue}?{option}=value url: '%env(resolve:BDF_QUEUE_CONNETION_URL)%' # Use those attribute to declare the connection if no url has been provided. driver: ~ vendor: ~ queue: ~ host: ~ port: ~ user: ~ password: ~ serializer: # The serializer ID. This ID will be prefix by "bdf_queue.serializer". Defined values: native, bdf, bdf_json. id: 'native' # The serializer service ID (without '@'). #service : ~ # Options of the connection. See https://github.com/b2pweb/bdf-queue for the list of available options. options: #key: ~ # Use a custom service to create your connection (with '@'). # Use the Bdf\QueueBundle\ConnectionFactory\ConnectionDriverFactory::createDriver() by default. connection_factory: ~ destinations: bus: # A URL with destination information; Format: [queue|queues|topic]://{connection}/{queue} url: 'queue://gearman/bus' consumer: # Set unique handler as outlet receiver handler: 'var_dump' # Retry failed jobs (i.e. throwing an exception) #retry: 0 # Limit the number of received message. When the limit is reached, the consumer is stopped #max: 2 # Limit the received message rate #limit: 100 # Limit the total memory usage of the current runtime in bytes. When the limit is reached, the consumer is stopped #memory: 128 # Store the failed messages #save: true # Disable the reset of services between messages #no_reset: true # Catch all exceptions to ensure that the consumer will no crash (and will silently fail) #no_failure: true # Stops consumption when the destination is empty (i.e. no messages are received during the waiting duration) #stop_when_empty: true # Set auto discover as outlet receiver. The message should contain target hint. #auto_handle: true # Define your own middleware. They should be added in the receiver factory. # See the Bdf\Queue\Consumer\Receiver\Builder\ReceiverFactory::addFactory() #middlewares: # - 'bench'
5 创建你的接收器
如果已激活参数autoconfigure
,你可以实现接口Bdf\QueueBundle\Consumption\ReceiverFactoryProviderInterface
来自动注册接收器工厂。否则,使用标签bdf_queue.receiver_factory
。
示例
services: FooReceiverFactory: class: 'FooReceiverFactory' tags: ['bdf_queue.receiver_factory']
6 创建你的连接
如果已激活参数autoconfigure
,你可以实现接口Bdf\QueueBundle\ConnectionFactory\ConnectionDriverConfiguratorInterface
来自动注册连接工厂。否则,使用标签bdf_queue.driver_configurator
。
示例
services: FooConnectionFactory: class: 'FooConnectionFactory' tags: ['bdf_queue.driver_configurator']