rxthunder/rabbitmq

RxThunder 的 RabbitMQ 库

0.2.2 2020-03-11 16:45 UTC

This package is auto-updated.

Last update: 2024-09-12 02:37:49 UTC


README

Latest Stable Version Total Downloads License

Build

安装

composer install rxthunder/rabbitmq

设置

首先,您必须向您的 .env 文件中添加新的密钥

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

然后配置新参数以注入到容器中

# 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'));

最后,您必须在容器中注册一个 RxNet/RabbitMq 客户端实例。

您可以创建自己的工厂,但默认工厂已嵌入到插件中,使用 voryx/event-loop 静态获取器。

# 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/*');

或者,如果您更喜欢,可以包括

# config/services.php

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

利润

您得到了新的控制台!

php vendor/bin/thunder