psyllium/amqp

There is no license information available for the latest version (6.4) of this package.

Symfony psyllium adapter for amqp

Installs: 106

Dependents: 0

Suggesters: 0

Security: 0

Type:symfony-bundle

6.4 2024-03-18 13:18 UTC

This package is not auto-updated.

Last update: 2024-05-28 18:52:36 UTC


README

Getting Started

This package is a part of Psyllium library. It provides a simple way to use RabbitMQ in your application. Allows you to define listeners and message producers in the queue system.

Install

To install the package you will need to be using Composer in your project. To install it please see the docs.

composer require psyllium/amqp

Enable the Bundle

Enable it by adding it to the list of registered bundles in the Kernel.php file of your project:

config/bundles.php

return [
    Psyllium\Amqp\PsylliumAmqp::class => ['all' => true]
];

config/packages/psyllium_amqp.yaml

psyllium:
  rabbitmq:
    hostname: '%hostname%'
    port: '%port%'
    user: '%user%'
    pass: '%password%'

Configure

In this way, you can create producers and listeners who will use the connection to the queuing system generated by the bundle.

config/services.yaml

psyllium.rabbitmq.listener:
  class: 'Psyllium\Amqp\Infrastructure\RabbitMQ\Listener'
  factory: ['@Psyllium\Amqp\Infrastructure\RabbitMQ\ListenerFactory', 'create']
  arguments:
    - '%queue_name%'

config/services.yaml

psyllium.rabbitmq.producer:
  class: 'Psyllium\Amqp\Infrastructure\RabbitMQ\Producer'
  factory: [ '@Psyllium\Amqp\Infrastructure\RabbitMQ\ProducerFactory', 'create' ]
  arguments:
    - '%exchange_name%'

How to use in code?

Listener:

$this->listener->listen(
    function (AMQPMessage $message): void {
        $message->getBody()
        // do something with message
        $message->ack();
    }
);

Producer:

Definde class that implements EventInterface

use Psyllium\Amqp\Domain\EventModel\EventInterface;

class Example implements EventInterface

Send message to queue

$this->producer->produce(
    new Example()
);