rxthunder/rabbitmq

RabbitMQ library for RxThunder

0.2.2 2020-03-11 16:45 UTC

This package is auto-updated.

Last update: 2024-11-12 02:58:04 UTC


README

Latest Stable Version Total Downloads License

Build

Installation

composer install rxthunder/rabbitmq

Setup

First you must add new secrets in your .env files

# .env
RABBIT_HOST=
RABBIT_PORT=
RABBIT_VHOST=
RABBIT_USER=
RABBIT_PASSWORD=

Then configure new parameters to be injected in the container

# config/parameters.php

$container->setParameter('rabbit.host', getenv('RABBIT_HOST'));
$container->setParameter('rabbit.port', getenv('RABBIT_PORT'));
$container->setParameter('rabbit.vhost', getenv('RABBIT_VHOST'));
$container->setParameter('rabbit.user', getenv('RABBIT_USER'));
$container->setParameter('rabbit.password', getenv('RABBIT_PASSWORD'));

Finally you must register an instance of RxNet/RabbitMq client in the container.

You can do your own factory but a default one is embed in the plugin using the voryx/event-loop static getter.

# config/services.php

use Rxnet\RabbitMq\Client;
use RxThunder\RabbitMQ\Factory;

$asynchRabbitMQDefinition = $container->register(Client::class)
    ->setFactory([Factory::class, 'createWithVoryxEventLoop'])
    ->addArgument('%rabbit.host%')
    ->addArgument('%rabbit.port%')
    ->addArgument('%rabbit.vhost%')
    ->addArgument('%rabbit.user%')
    ->addArgument('%rabbit.password%')
    ->setPublic(false)
    ->setAutowired(false)
    ->setAutoconfigured(true);
# config/services.php

require_once __DIR__ . '/../vendor/rxthunder/rabbitmq/config/services.php';

// Register RabbitMQ consoles
$consoleDefinition = new Definition();
$consoleDefinition->setPublic(true);
$consoleDefinition->setAutowired(true);
$consoleDefinition->setAutoconfigured(true);

$this->registerClasses($consoleDefinition, 'RxThunder\\RabbitMQ\\Console\\', '../vendor/rxthunder/rabbitmq/src/Console/*');

Or if you prefer you can include

# config/services.php

require_once __DIR__ . '/../vendor/rxthunder/rabbitmq/config/services.php';
require_once __DIR__ . '/../vendor/rxthunder/rabbitmq/config/consoles.php';

Profit

You got new consoles !

php vendor/bin/thunder