Repository navigation
Expand file tree
/
Copy pathmodule.php
More file actions
64 lines (59 loc) · 3.01 KB
/
Copy pathmodule.php
File metadata and controls
64 lines (59 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
use Marko\Config\ConfigRepositoryInterface;
use Marko\Core\Container\ContainerInterface;
use Marko\Queue\FailedJobRepositoryInterface;
use Marko\Queue\JobEnvelope;
use Marko\Queue\JobIdGenerator;
use Marko\Queue\QueueConfig;
use Marko\Queue\QueueInterface;
use Marko\Queue\Rabbitmq\Exceptions\RabbitmqException;
use Marko\Queue\Rabbitmq\Exchange\ExchangeConfig;
use Marko\Queue\Rabbitmq\Exchange\ExchangeType;
use Marko\Queue\Rabbitmq\RabbitmqConnection;
use Marko\Queue\Rabbitmq\RabbitmqFailedJobRepository;
use Marko\Queue\Rabbitmq\RabbitmqQueue;
return [
'bindings' => [
QueueInterface::class => static function (ContainerInterface $container): QueueInterface {
return new RabbitmqQueue(
connection: $container->get(RabbitmqConnection::class),
exchangeConfig: $container->get(ExchangeConfig::class),
jobEnvelope: $container->get(JobEnvelope::class),
defaultQueue: $container->get(QueueConfig::class)->queue(),
jobIdGenerator: $container->get(JobIdGenerator::class),
);
},
FailedJobRepositoryInterface::class => RabbitmqFailedJobRepository::class,
RabbitmqConnection::class => static function (ContainerInterface $container): RabbitmqConnection {
$config = $container->get(ConfigRepositoryInterface::class);
// An app config that sets tls to null removes the key (ConfigMerger
// unsets null overrides), so a missing key also means plain TCP.
$tls = $config->has(key: 'queue-rabbitmq.tls') ? $config->get(key: 'queue-rabbitmq.tls') : null;
return new RabbitmqConnection(
host: $config->getString(key: 'queue-rabbitmq.host'),
port: $config->getInt(key: 'queue-rabbitmq.port'),
user: $config->getString(key: 'queue-rabbitmq.user'),
password: $config->getString(key: 'queue-rabbitmq.password'),
vhost: $config->getString(key: 'queue-rabbitmq.vhost'),
tlsOptions: $tls === null ? null : $config->getArray(key: 'queue-rabbitmq.tls'),
);
},
ExchangeConfig::class => static function (ContainerInterface $container): ExchangeConfig {
$config = $container->get(ConfigRepositoryInterface::class);
$type = $config->getString(key: 'queue-rabbitmq.exchange.type');
return new ExchangeConfig(
name: $config->getString(key: 'queue-rabbitmq.exchange.name'),
type: ExchangeType::tryFrom($type) ?? throw RabbitmqException::invalidExchangeType(
$type,
array_map(static fn (ExchangeType $case): string => $case->value, ExchangeType::cases()),
),
durable: $config->getBool(key: 'queue-rabbitmq.exchange.durable'),
autoDelete: $config->getBool(key: 'queue-rabbitmq.exchange.auto_delete'),
);
},
],
'singletons' => [
RabbitmqConnection::class,
],
];