b2pweb/bdf-queue-bundle

Symfony BdfQueueBundle

安装次数: 2,170

依赖者: 0

建议者: 0

安全性: 0

星星: 0

关注者: 2

分支: 0

公开问题: 1

类型:symfony-bundle

v1.4.0 2024-03-12 11:29 UTC

README

build Scrutinizer Code Quality Packagist Version Total Downloads

安装

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']