40 lines
1014 B
PHP
40 lines
1014 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Diffhead\PHP\LaravelRabbitMQ\Service;
|
|
|
|
use Diffhead\PHP\LaravelRabbitMQ\Object\Connection;
|
|
use Diffhead\PHP\LaravelRabbitMQ\Object\Publishing;
|
|
use RuntimeException;
|
|
|
|
class Configuration
|
|
{
|
|
public function getConnection(string $connection = 'default'): Connection
|
|
{
|
|
$config = config(sprintf('rabbitmq.connections.%s', $connection));
|
|
|
|
if (empty($config)) {
|
|
throw new RuntimeException(
|
|
sprintf('Not found rabbitmq config for connection %s', $connection)
|
|
);
|
|
}
|
|
|
|
return new Connection(
|
|
$config['host'],
|
|
(int) $config['port'],
|
|
$config['user'],
|
|
$config['password'],
|
|
$config['vhost'],
|
|
);
|
|
}
|
|
|
|
public function getPublishing(): Publishing
|
|
{
|
|
return new Publishing(
|
|
config('rabbitmq.event.publishing.connection', 'sync'),
|
|
config('rabbitmq.event.publishing.queue', 'default'),
|
|
);
|
|
}
|
|
}
|