|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ccovey\RabbitMQ; |
|
4
|
|
|
|
|
5
|
|
|
use Ccovey\RabbitMQ\Consumer\Consumable; |
|
6
|
|
|
use Ccovey\RabbitMQ\Producer\Publishable; |
|
7
|
|
|
use PhpAmqpLib\Channel\AMQPChannel; |
|
8
|
|
|
use PhpAmqpLib\Message\AMQPMessage; |
|
9
|
|
|
|
|
10
|
|
|
class Channel implements ChannelInterface |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var AMQPChannel |
|
14
|
|
|
*/ |
|
15
|
|
|
private $channel; |
|
16
|
|
|
|
|
17
|
19 |
|
public function __construct(AMQPChannel $channel) |
|
18
|
|
|
{ |
|
19
|
19 |
|
$this->channel = $channel; |
|
20
|
19 |
|
} |
|
21
|
|
|
|
|
22
|
2 |
|
public function wait() |
|
23
|
|
|
{ |
|
24
|
2 |
|
return $this->channel->wait(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
2 |
|
public function acknowledge(string $deliveryTag, bool $multiple = false) |
|
28
|
|
|
{ |
|
29
|
2 |
|
return $this->channel->basic_ack($deliveryTag, $multiple); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
3 |
|
public function nack(string $deliveryTag, bool $multiple = false, bool $requeue = false) |
|
33
|
|
|
{ |
|
34
|
3 |
|
return $this->channel->basic_nack($deliveryTag, $multiple, $requeue); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
public function consume(Consumable $consumable) : ChannelInterface |
|
38
|
|
|
{ |
|
39
|
2 |
|
$this->channel->basic_consume( |
|
40
|
2 |
|
$consumable->getQueueName(), |
|
41
|
2 |
|
$consumable->getConsumerTag(), |
|
42
|
2 |
|
$consumable->isNoLocal(), |
|
43
|
2 |
|
$consumable->isNoAck(), |
|
44
|
2 |
|
$consumable->isExclusive(), |
|
45
|
2 |
|
$consumable->isNoWait(), |
|
46
|
2 |
|
$consumable->getCallback(), |
|
47
|
2 |
|
$consumable->getTicket(), |
|
48
|
2 |
|
$consumable->getArguments() |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
2 |
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
public function publish(Publishable $message) : ChannelInterface |
|
55
|
|
|
{ |
|
56
|
2 |
|
if ($message->isDelayed()) { |
|
57
|
|
|
$queue = new Queue($message->getQueueName(), $message->getDelayedExchanged()); |
|
58
|
|
|
$message->setExchange($message->getDelayedExchanged()); |
|
|
|
|
|
|
59
|
|
|
$this->bindQueue($queue); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
2 |
|
$this->channel->basic_publish( |
|
63
|
2 |
|
$message->getMessage(), |
|
64
|
2 |
|
$message->getExchange(), |
|
65
|
2 |
|
$message->getQueueName(), |
|
66
|
2 |
|
$message->isMandatory(), |
|
67
|
2 |
|
$message->isImmediate(), |
|
68
|
2 |
|
$message->getTicket() |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
2 |
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param $prefetchSize |
|
76
|
|
|
* @param int $prefetchCount |
|
77
|
|
|
* @param $aGlobal |
|
78
|
|
|
* |
|
79
|
|
|
* @return mixed |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function basicQos($prefetchSize = null, int $prefetchCount = 1, $aGlobal = null) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$this->channel->basic_qos($prefetchSize, $prefetchCount, $aGlobal); |
|
84
|
|
|
|
|
85
|
1 |
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
2 |
View Code Duplication |
public function declareQueue(Queue $queue) : ChannelInterface |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
2 |
|
$this->channel->queue_declare( |
|
91
|
2 |
|
$queue->getQueueName(), |
|
92
|
2 |
|
$queue->isPassive(), |
|
93
|
2 |
|
$queue->isDurable(), |
|
94
|
2 |
|
$queue->isExclusive(), |
|
95
|
2 |
|
$queue->isAutoDelete(), |
|
96
|
2 |
|
$queue->isNoWait(), |
|
97
|
2 |
|
$queue->getArguments(), |
|
|
|
|
|
|
98
|
2 |
|
$queue->getTicket() |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
2 |
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
2 |
|
public function bindQueue(Queue $queue) : ChannelInterface |
|
105
|
|
|
{ |
|
106
|
2 |
|
$this->channel->queue_bind( |
|
107
|
2 |
|
$queue->getQueueName(), |
|
108
|
2 |
|
$queue->getExchange(), |
|
109
|
2 |
|
$queue->getQueueName(), |
|
110
|
2 |
|
$queue->isNoWait(), |
|
111
|
2 |
|
$queue->getArguments(), |
|
|
|
|
|
|
112
|
2 |
|
$queue->getTicket() |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
2 |
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
2 |
View Code Duplication |
public function declareExchange(Exchange $exchange) : ChannelInterface |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
2 |
|
$this->channel->exchange_declare( |
|
121
|
2 |
|
$exchange->getExchange(), |
|
122
|
2 |
|
$exchange->getType(), |
|
123
|
2 |
|
$exchange->isPassive(), |
|
124
|
2 |
|
$exchange->isDurable(), |
|
125
|
2 |
|
$exchange->isAutoDelete(), |
|
126
|
2 |
|
$exchange->isInternal(), |
|
127
|
2 |
|
$exchange->isNoWait(), |
|
128
|
2 |
|
$exchange->getArguments(), |
|
129
|
2 |
|
$exchange->getTicket() |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
2 |
|
return $this; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return array |
|
137
|
|
|
*/ |
|
138
|
2 |
|
public function getCallbacks() : array |
|
139
|
|
|
{ |
|
140
|
2 |
|
return $this->channel->callbacks; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
1 |
|
public function setCallbacks(array $callbacks = []) |
|
144
|
|
|
{ |
|
145
|
1 |
|
$this->channel->callbacks = $callbacks; |
|
146
|
1 |
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param Consumable $consumable |
|
150
|
|
|
* |
|
151
|
|
|
* @return AMQPMessage|null |
|
152
|
|
|
*/ |
|
153
|
1 |
|
public function getMessage(Consumable $consumable) |
|
154
|
|
|
{ |
|
155
|
1 |
|
return $this->channel->basic_get($consumable->getQueueName(), $consumable->isNoAck(), $consumable->getTicket()); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
2 |
|
public function getQueueSize(Queue $queue) : int |
|
159
|
|
|
{ |
|
160
|
2 |
|
$declaredQueue = $this->channel->queue_declare( |
|
161
|
2 |
|
$queue->getQueueName(), |
|
162
|
2 |
|
true, |
|
163
|
2 |
|
$queue->isDurable(), |
|
164
|
2 |
|
$queue->isExclusive(), |
|
165
|
2 |
|
$queue->isAutoDelete(), |
|
166
|
2 |
|
$queue->isNoWait(), |
|
167
|
2 |
|
$queue->getArguments(), |
|
|
|
|
|
|
168
|
2 |
|
$queue->getTicket() |
|
169
|
|
|
); |
|
170
|
|
|
|
|
171
|
2 |
|
return $declaredQueue[1] ?? 0; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
2 |
|
public function deleteQueue(string $queueName) : ChannelInterface |
|
175
|
|
|
{ |
|
176
|
2 |
|
$this->channel->queue_delete($queueName); |
|
177
|
|
|
|
|
178
|
2 |
|
return $this; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
2 |
|
public function deleteExchange(string $queueName) : ChannelInterface |
|
182
|
|
|
{ |
|
183
|
2 |
|
$this->channel->exchange_delete($queueName); |
|
184
|
|
|
|
|
185
|
2 |
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.