PHPackages                             roslov/queue-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. roslov/queue-bundle

ActiveSymfony-bundle[Queues &amp; Workers](/categories/queues)

roslov/queue-bundle
===================

Queue bundle

2.2.1(5mo ago)1725[11 issues](https://github.com/roslov/queue-bundle/issues)[2 PRs](https://github.com/roslov/queue-bundle/pulls)MITPHPPHP ^8.1CI passing

Since Mar 25Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/roslov/queue-bundle)[ Packagist](https://packagist.org/packages/roslov/queue-bundle)[ RSS](/packages/roslov-queue-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (10)Versions (10)Used By (0)

Queue Bundle
============

[](#queue-bundle)

[![Latest Stable Version](https://camo.githubusercontent.com/245bcc28074e18fa6fdfaa80aaf4f4320c20cb71863afb805adf73b1823e74f1/68747470733a2f2f706f7365722e707567782e6f72672f726f736c6f762f71756575652d62756e646c652f76)](https://packagist.org/packages/roslov/queue-bundle)[![Total Downloads](https://camo.githubusercontent.com/e1535c02af4915e8b4018f7041f8d3186e2a849613dae132394e012dd347ef29/68747470733a2f2f706f7365722e707567782e6f72672f726f736c6f762f71756575652d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/roslov/queue-bundle)[![License](https://camo.githubusercontent.com/461de386a4455ba9101533f46fb07605e847e85feb7b2ea0560336b92a12bf63/68747470733a2f2f706f7365722e707567782e6f72672f726f736c6f762f71756575652d62756e646c652f6c6963656e7365)](https://packagist.org/packages/roslov/queue-bundle)[![PHP Version Require](https://camo.githubusercontent.com/39815e27dc457e4ff52f7bb9fdde2d92e24996430e61df5c6bf5fcc161e203c3/68747470733a2f2f706f7365722e707567782e6f72672f726f736c6f762f71756575652d62756e646c652f726571756972652f706870)](https://packagist.org/packages/roslov/queue-bundle)

This package provides the classes needed to work with RabbitMQ.

It is based on [RabbitMQ bundle](https://github.com/php-amqplib/RabbitMqBundle).

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Symfony 6.0 or higher
- Doctrine bundle (optional)
- MySQL DB (optional)

Installation and usage
----------------------

[](#installation-and-usage)

### Default bundle configuration

[](#default-bundle-configuration)

The package could be installed with composer:

```
composer require roslov/queue-bundle
```

Then change the default settings by creating `config/packages/roslov_queue.yaml` with the content below.

```
# config/packages/roslov_queue.yaml
roslov_queue:
  # Microservice name. This value will be used as a source of your published message
  service_name: my_service
  # Set this value to `true` if you’re using the SSL connection to RabbitMQ (for example, in AWS)
  ssl_enabled: false
  # PSR-3 logger service
  logger: logger
  # Entity manager service. If you do not produce messages, set it to `null` (`~`)
  entity_manager: doctrine.orm.default_entity_manager
  # Event processor
  event_processor:
    # Whether the event processor is enabled. If disabled, no events will be sent or saved
    enabled: false
    # Whether the event processor uses instant delivery. If disabled, the event processor is used as a transactional
    # outbox
    instant_delivery: true
    # Delayed delivery subscriber. If disabled, the events will be stored but not sent (useful for tests)
    delayed_delivery_subscriber: true
  # RPC client
  rpc_client:
    # Whether an RPC client should be created
    enabled: false
    # RabbitMQ connection
    connection: default
  # RPC server
  rpc_server:
    # Whether RPC server should be created
    enabled: false
    # RabbitMQ connection
    connection: default
    # Exchange name
    exchange: rpc_exchange
    # Setup callable. If you need to run some processes before running each handler (like DB connection refresh), add
    # the callable service here
    setup: ~
    # Handlers
    handlers: []
      # Put your handlers here:
      # App\Dto\Queue\GetUserCommand: App\Rpc\UserHandler
  # Message type to payload mapping. Extend this array with your payloads
  payload_mapping:
    Error: Roslov\QueueBundle\Dto\Error
    Trigger: Roslov\QueueBundle\Dto\Trigger
    Response.Empty: Roslov\QueueBundle\Dto\EmptyResponse
    Exception.Thrown: Roslov\QueueBundle\Dto\ExceptionThrown
    # Put your payloads here
  # By default, exception_subscriber is turned off
  exception_subscriber:
    # Whether exception subscriber should be enabled. If enabled, `exception_sender.exchange_options` is required
    enabled: false
    # Exception validator callable. If you need to check whether an exception subscriber should execute its code with
    # the given exception, add the callable service here. It must return `true` if the exception is OK and the
    # notification should be sent, or `false` if passed exception is not OK and should not be notified.
    # Check the example of the exception validator class below
    exception_validator: ~
  # Exception sender
  exception_sender:
    # RabbitMQ connection
    connection: default
    # Put exchange options here. This option is required if you either enabled `exception_subscriber` or use this sender
    # manually
    exchange_options: { name: 'exchange_name', type: topic }
```

### RabbitMQ configuration

[](#rabbitmq-configuration)

This package also installs [RabbitMQ bundle](https://github.com/php-amqplib/RabbitMqBundle). So first, you need to configure the RabbitMQ bundle. Follow its documentation. For example:

```
# config/packages/old_sound_rabbit_mq.yaml
old_sound_rabbit_mq:
  # RabbitMQ connection config
  connections:
    default:
      url: '%env(RABBITMQ_URL)%'
      lazy: true
      connection_timeout: 5
      read_write_timeout: 60
      keepalive: false
      heartbeat: 30
      # Use this parameter only if you need to use SSL connection to RabbitMQ
      connection_parameters_provider: roslov_queue.rabbitmq.simple_ssl_context_provider
  # Producers (if used)
  producers:
    user_created:
      class: App\Producer\UserCreatedProducer
      connection: default
      exchange_options: { name: 'user', type: topic, auto_delete: false, durable: true }
      enable_logger: true
    # ...other producers
  # Multiple consumers
  multiple_consumers:
    main:
      connection: default
      exchange_options: { name: 'main', type: direct, auto_delete: false, durable: true }
      enable_logger: true
      queues:
        user-created:
          name: user_created
          routing_keys:
            - user-created
          callback: App\Consumer\UserCreatedConsumer
        # other consumers
```

### Consumers and producers

[](#consumers-and-producers)

Create DTOs that will be used in consumers and producers, and add them to `roslov_queue.payload_mapping` (see examples).

Create a consumer that uses `Roslov\QueueBundle\Serializer\MessagePayloadSerializer` as a serializer:

```
