|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\AMQP\Client\Channel\Queue; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\AMQP\{ |
|
7
|
|
|
Client\Channel\Queue as QueueInterface, |
|
8
|
|
|
Model\Queue\Declaration, |
|
9
|
|
|
Model\Queue\DeclareOk, |
|
10
|
|
|
Model\Queue\Deletion, |
|
11
|
|
|
Model\Queue\DeleteOk, |
|
12
|
|
|
Model\Queue\Binding, |
|
13
|
|
|
Model\Queue\Unbinding, |
|
14
|
|
|
Model\Queue\Purge, |
|
15
|
|
|
Model\Queue\PurgeOk, |
|
16
|
|
|
Model\Count, |
|
17
|
|
|
Transport\Connection, |
|
18
|
|
|
Transport\Frame\Channel |
|
19
|
|
|
}; |
|
20
|
|
|
|
|
21
|
|
|
final class Queue implements QueueInterface |
|
22
|
|
|
{ |
|
23
|
|
|
private $connection; |
|
24
|
|
|
private $channel; |
|
25
|
|
|
|
|
26
|
6 |
|
public function __construct(Connection $connection, Channel $channel) |
|
27
|
|
|
{ |
|
28
|
6 |
|
$this->connection = $connection; |
|
29
|
6 |
|
$this->channel = $channel; |
|
30
|
6 |
|
} |
|
31
|
|
|
|
|
32
|
5 |
|
public function declare(Declaration $command): ?DeclareOk |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
5 |
|
$this->connection->send( |
|
35
|
5 |
|
$this->connection->protocol()->queue()->declare( |
|
36
|
5 |
|
$this->channel, |
|
37
|
5 |
|
$command |
|
38
|
|
|
) |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
5 |
|
if (!$command->shouldWait()) { |
|
42
|
1 |
|
return null; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
5 |
|
$frame = $this->connection->wait('queue.declare-ok'); |
|
46
|
|
|
|
|
47
|
5 |
|
return new DeclareOk( |
|
|
|
|
|
|
48
|
5 |
|
(string) $frame->values()->get(0)->original(), |
|
49
|
5 |
|
new Count($frame->values()->get(1)->original()->value()), |
|
50
|
5 |
|
new Count($frame->values()->get(2)->original()->value()) |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
public function delete(Deletion $command): ?DeleteOk |
|
55
|
|
|
{ |
|
56
|
1 |
|
$this->connection->send( |
|
57
|
1 |
|
$this->connection->protocol()->queue()->delete( |
|
58
|
1 |
|
$this->channel, |
|
59
|
1 |
|
$command |
|
60
|
|
|
) |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
1 |
|
if (!$command->shouldWait()) { |
|
64
|
1 |
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
$frame = $this->connection->wait('queue.delete-ok'); |
|
68
|
|
|
|
|
69
|
1 |
|
return new DeleteOk(new Count( |
|
70
|
1 |
|
$frame->values()->first()->original()->value() |
|
71
|
|
|
)); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
public function bind(Binding $command): QueueInterface |
|
75
|
|
|
{ |
|
76
|
1 |
|
$this->connection->send( |
|
77
|
1 |
|
$this->connection->protocol()->queue()->bind( |
|
78
|
1 |
|
$this->channel, |
|
79
|
1 |
|
$command |
|
80
|
|
|
) |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
1 |
|
if ($command->shouldWait()) { |
|
84
|
1 |
|
$this->connection->wait('queue.bind-ok'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
return $this; |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
public function unbind(Unbinding $command): QueueInterface |
|
91
|
|
|
{ |
|
92
|
|
|
$this |
|
93
|
1 |
|
->connection |
|
94
|
1 |
|
->send($this->connection->protocol()->queue()->unbind( |
|
95
|
1 |
|
$this->channel, |
|
96
|
1 |
|
$command |
|
97
|
|
|
)) |
|
98
|
1 |
|
->wait('queue.unbind-ok'); |
|
99
|
|
|
|
|
100
|
1 |
|
return $this; |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
public function purge(Purge $command): ?PurgeOk |
|
104
|
|
|
{ |
|
105
|
1 |
|
$this->connection->send( |
|
106
|
1 |
|
$this->connection->protocol()->queue()->purge( |
|
107
|
1 |
|
$this->channel, |
|
108
|
1 |
|
$command |
|
109
|
|
|
) |
|
110
|
|
|
); |
|
111
|
|
|
|
|
112
|
1 |
|
if (!$command->shouldWait()) { |
|
113
|
1 |
|
return null; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
1 |
|
$frame = $this->connection->wait('queue.purge-ok'); |
|
117
|
|
|
|
|
118
|
1 |
|
return new PurgeOk(new Count( |
|
119
|
1 |
|
$frame->values()->first()->original()->value() |
|
120
|
|
|
)); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|