1 | <?php |
||
8 | class Client |
||
9 | { |
||
10 | /** |
||
11 | * RabbitMq host. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | private $host; |
||
16 | |||
17 | /** |
||
18 | * RabbitMq port. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | private $port; |
||
23 | |||
24 | /** |
||
25 | * RabbitMq user. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | private $user; |
||
30 | |||
31 | /** |
||
32 | * RabbitMq password. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $password; |
||
37 | |||
38 | /** |
||
39 | * It's for QOS prefetch-size http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos. |
||
40 | * |
||
41 | * @var int |
||
42 | */ |
||
43 | private $prefetchSize = null; |
||
44 | |||
45 | /** |
||
46 | * It's for QOS prefetch-count http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos. |
||
47 | * |
||
48 | * @var int |
||
49 | */ |
||
50 | private $prefetchCount = null; |
||
51 | |||
52 | /** |
||
53 | * It's for QOS global http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos. |
||
54 | * |
||
55 | * @var int |
||
56 | */ |
||
57 | private $aGlobal = null; |
||
58 | |||
59 | /** |
||
60 | * RabbitMq connection. |
||
61 | * |
||
62 | * @var AMQPStreamConnection |
||
63 | */ |
||
64 | private $connection = null; |
||
65 | |||
66 | /** |
||
67 | * RabbitMq channel. |
||
68 | * |
||
69 | * @var \AMQPChannel |
||
70 | */ |
||
71 | private $channel = null; |
||
72 | |||
73 | /** |
||
74 | * List of RabbitMq object. |
||
75 | * |
||
76 | * @var RabbitMqObjectInterface[] |
||
77 | */ |
||
78 | private $rabbitMqObjects = []; |
||
79 | |||
80 | /** |
||
81 | * Maximum connection's retry |
||
82 | **/ |
||
83 | const MAX_RETRY = 10; |
||
84 | |||
85 | /** |
||
86 | * current retry amount |
||
87 | **/ |
||
88 | private static $retry = 0; |
||
89 | /** |
||
90 | * time in seconds to wait between each retry |
||
91 | **/ |
||
92 | const WAIT_TIME = 30; |
||
93 | |||
94 | public function __construct($host, $port, $user, $password) |
||
101 | |||
102 | /** |
||
103 | * Get prefetch size for QOS. |
||
104 | */ |
||
105 | public function getPrefetchSize() |
||
109 | |||
110 | /** |
||
111 | * Set prefetch size |
||
112 | * It's for QOS prefetch-size http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos. |
||
113 | * |
||
114 | * @param int $prefetchSize |
||
115 | */ |
||
116 | public function setPrefetchSize($prefetchSize) |
||
122 | |||
123 | /** |
||
124 | * Get prefetch count for QOS. |
||
125 | */ |
||
126 | public function getPrefetchCount() |
||
130 | |||
131 | /** |
||
132 | * Set prefetch size |
||
133 | * It's for QOS prefetch-size http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos. |
||
134 | * |
||
135 | * @param int $prefetchCount |
||
136 | */ |
||
137 | public function setPrefetchCount($prefetchCount) |
||
143 | |||
144 | /** |
||
145 | * Get a global for QOS. |
||
146 | */ |
||
147 | public function getAGlobal() |
||
151 | |||
152 | /** |
||
153 | * Set global |
||
154 | * It's for QOS prefetch-size http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos. |
||
155 | * |
||
156 | * @param int $aGlobal |
||
157 | */ |
||
158 | public function setAGlobal($aGlobal) |
||
164 | |||
165 | /** |
||
166 | * Set RabbitMq object. |
||
167 | * |
||
168 | * @param RabbitMqObjectInterface[] $rabbitMqObjects |
||
169 | */ |
||
170 | public function setRabbitMqObjects(array $rabbitMqObjects) |
||
174 | |||
175 | public function register(RabbitMqObjectInterface $object) |
||
181 | |||
182 | /** |
||
183 | * Function used to create $this->connection |
||
184 | * handle connection's retry in case of the rabbitmq server is not ready yet |
||
185 | **/ |
||
186 | private function createConnection() |
||
199 | |||
200 | /** |
||
201 | * Connection to the RabbitMq service with AMQPStreamConnection. |
||
202 | * |
||
203 | * @return AMQPChannel |
||
204 | */ |
||
205 | public function getChannel() |
||
222 | |||
223 | /** |
||
224 | * Returns the list of registered queues. |
||
225 | * |
||
226 | * @return QueueInterface[] |
||
227 | */ |
||
228 | public function getQueues() |
||
234 | } |
||
235 |