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
|
|
|
|
9
|
|
|
class Channel implements ChannelInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var AMQPChannel |
13
|
|
|
*/ |
14
|
|
|
private $channel; |
15
|
|
|
|
16
|
13 |
|
public function __construct(AMQPChannel $channel) |
17
|
|
|
{ |
18
|
13 |
|
$this->channel = $channel; |
19
|
13 |
|
} |
20
|
|
|
|
21
|
1 |
|
public function wait() |
22
|
|
|
{ |
23
|
1 |
|
return $this->channel->wait(); |
24
|
|
|
} |
25
|
|
|
|
26
|
1 |
|
public function acknowledge(string $deliveryTag, bool $multiple = false) |
27
|
|
|
{ |
28
|
1 |
|
return $this->channel->basic_ack($deliveryTag, $multiple); |
29
|
|
|
} |
30
|
|
|
|
31
|
3 |
|
public function nack(string $deliveryTag, bool $multiple = false, bool $requeue = false) |
32
|
|
|
{ |
33
|
3 |
|
return $this->channel->basic_nack($deliveryTag, $multiple, $requeue); |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
public function consume(Consumable $consumable) : ChannelInterface |
37
|
|
|
{ |
38
|
1 |
|
$this->channel->basic_consume( |
39
|
1 |
|
$consumable->getQueueName(), |
40
|
1 |
|
$consumable->getConsumerTag(), |
41
|
1 |
|
$consumable->isNoLocal(), |
42
|
1 |
|
$consumable->isNoAck(), |
43
|
1 |
|
$consumable->isExclusive(), |
44
|
1 |
|
$consumable->isNoWait(), |
45
|
1 |
|
$consumable->getCallback(), |
46
|
1 |
|
$consumable->getTicket(), |
47
|
1 |
|
$consumable->getArguments() |
48
|
|
|
); |
49
|
|
|
|
50
|
1 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
public function publish(Publishable $message) : ChannelInterface |
54
|
|
|
{ |
55
|
1 |
|
if ($message->isDelayed()) { |
56
|
|
|
$queue = new Queue($message->getQueueName(), $message->getDelayedExchanged()); |
57
|
|
|
$message->setExchange($message->getDelayedExchanged()); |
|
|
|
|
58
|
|
|
$this->bindQueue($queue); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
$this->channel->basic_publish( |
62
|
1 |
|
$message->getMessage(), |
63
|
1 |
|
$message->getExchange(), |
64
|
1 |
|
$message->getQueueName(), |
65
|
1 |
|
$message->isMandatory(), |
66
|
1 |
|
$message->isImmediate(), |
67
|
1 |
|
$message->getTicket() |
68
|
|
|
); |
69
|
|
|
|
70
|
1 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param $prefetchSize |
75
|
|
|
* @param int $prefetchCount |
76
|
|
|
* @param $aGlobal |
77
|
|
|
* |
78
|
|
|
* @return mixed |
79
|
|
|
*/ |
80
|
1 |
|
public function basicQos($prefetchSize = null, int $prefetchCount = 1, $aGlobal = null) |
81
|
|
|
{ |
82
|
1 |
|
$this->channel->basic_qos($prefetchSize, $prefetchCount, $aGlobal); |
83
|
|
|
|
84
|
1 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param Queue $queue |
89
|
|
|
* |
90
|
|
|
* @return ChannelInterface |
91
|
|
|
*/ |
92
|
1 |
View Code Duplication |
public function declareQueue(Queue $queue) : ChannelInterface |
|
|
|
|
93
|
|
|
{ |
94
|
1 |
|
$this->channel->queue_declare( |
95
|
1 |
|
$queue->getQueueName(), |
96
|
1 |
|
$queue->isPassive(), |
97
|
1 |
|
$queue->isDurable(), |
98
|
1 |
|
$queue->isExclusive(), |
99
|
1 |
|
$queue->isAutoDelete(), |
100
|
1 |
|
$queue->isNoWait(), |
101
|
1 |
|
$queue->getArguments(), |
|
|
|
|
102
|
1 |
|
$queue->getTicket() |
103
|
|
|
); |
104
|
|
|
|
105
|
1 |
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
1 |
|
public function bindQueue(Queue $queue) : ChannelInterface |
109
|
|
|
{ |
110
|
1 |
|
$this->channel->queue_bind( |
111
|
1 |
|
$queue->getQueueName(), |
112
|
1 |
|
$queue->getExchange(), |
113
|
1 |
|
$queue->getQueueName(), |
114
|
1 |
|
$queue->isNoWait(), |
115
|
1 |
|
$queue->getArguments(), |
|
|
|
|
116
|
1 |
|
$queue->getTicket() |
117
|
|
|
); |
118
|
|
|
|
119
|
1 |
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
1 |
View Code Duplication |
public function declareExchange(Exchange $exchange) : ChannelInterface |
|
|
|
|
123
|
|
|
{ |
124
|
1 |
|
$this->channel->exchange_declare( |
125
|
1 |
|
$exchange->getExchange(), |
126
|
1 |
|
$exchange->getType(), |
127
|
1 |
|
$exchange->isPassive(), |
128
|
1 |
|
$exchange->isDurable(), |
129
|
1 |
|
$exchange->isAutoDelete(), |
130
|
1 |
|
$exchange->isInternal(), |
131
|
1 |
|
$exchange->isNoWait(), |
132
|
1 |
|
$exchange->getArguments(), |
133
|
1 |
|
$exchange->getTicket() |
134
|
|
|
); |
135
|
|
|
|
136
|
1 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
1 |
|
public function getCallbacks() : array |
143
|
|
|
{ |
144
|
1 |
|
return $this->channel->callbacks; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function setCallbacks(array $callbacks = []) |
148
|
|
|
{ |
149
|
|
|
$this->channel->callbacks = $callbacks; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
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.