-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexplicitReturn.php
More file actions
35 lines (22 loc) · 813 Bytes
/
explicitReturn.php
File metadata and controls
35 lines (22 loc) · 813 Bytes
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
<?php
declare(strict_types=1);
use Thesis\Amqp\Client;
use Thesis\Amqp\Config;
use Thesis\Amqp\Message;
use Thesis\Amqp\PublishResult;
require_once __DIR__ . '/../vendor/autoload.php';
$client = new Client(Config::default());
$channel = $client->channel();
$channel->queueDelete('xxx');
$channel->confirmSelect();
$msg = new Message('abz');
$confirmation = $channel->publish($msg, routingKey: 'xxx', mandatory: true);
$result = $confirmation?->await();
if ($result === PublishResult::Unrouted) {
dump('Message cannot be routed. Creating queue explicitly...');
$channel->queueDeclare('xxx', durable: true);
}
$channel->publish($msg, routingKey: 'xxx', mandatory: true)?->await();
$msg = $channel->get('xxx');
dump("Now message '{$msg?->message->body}' was published.");
$client->disconnect();