-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBunnySetup.php
39 lines (31 loc) · 992 Bytes
/
BunnySetup.php
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
<?php
declare(strict_types=1);
namespace Telephantast\BunnyTransport;
use Telephantast\MessageBus\Async\TransportSetup;
use function React\Async\await;
/**
* @api
*/
final readonly class BunnySetup implements TransportSetup
{
public function __construct(
private BunnyConnectionPool $connectionPool,
) {}
/**
* @psalm-suppress MissingThrowsDocblock
*/
public function setup(array $exchangeToQueues): void
{
$channel = await($this->connectionPool->get()->channel());
foreach ($exchangeToQueues as $exchange => $queues) {
await($channel->exchangeDeclare($exchange, 'x-delayed-message', durable: true, arguments: [
'x-delayed-type' => 'fanout',
]));
foreach ($queues as $queue) {
await($channel->queueDeclare($queue, durable: true));
await($channel->queueBind($queue, $exchange));
}
}
await($channel->close());
}
}