b2pweb/bdf-queue-bundle

Symfony BdfQueueBundle

Installs: 1 824

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

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

This package is auto-updated.

Last update: 2024-04-12 11:43:25 UTC


README

build Scrutinizer Code Quality Packagist Version Total Downloads

Installation

1 Download the Bundle

Download the latest stable version of this bundle with composer:

    $ composer require b2pweb/bdf-queue-bundle

2 Enable the Bundle

Adding the following line in the config/bundles.php file of your project::

<?php
// config/bundles.php

return [
    // ...
    Bdf\QueueBundle\BdfQueueBundle::class => ['all' => true],
    // ...
];

3 Set environment

Add your dsn on the.env file

BDF_QUEUE_CONNETION_URL=gearman://root@127.0.0.1?client-timeout=10

4 Add configuration

Add a default config file to ./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 Create your receiver in consumption

If the parameter autoconfigure is activated you can implement the interface Bdf\QueueBundle\Consumption\ReceiverFactoryProviderInterface to have your receiver factory auto registered. Otherwise use the tag bdf_queue.receiver_factory.

ex:

services:
  FooReceiverFactory:
    class: 'FooReceiverFactory'
    tags: ['bdf_queue.receiver_factory']

6 Create your connection

If the parameter autoconfigure is activated you can implement the interface Bdf\QueueBundle\ConnectionFactory\ConnectionDriverConfiguratorInterface to have your connection factory auto registered. Otherwise use the tag bdf_queue.driver_configurator.

ex:

services:
  FooConnectionFactory:
    class: 'FooConnectionFactory'
    tags: ['bdf_queue.driver_configurator']