@@ -20,15 +20,10 @@ class RabbitMQQueue extends Queue implements QueueContract
2020 */
2121 const ATTEMPT_COUNT_HEADERS_KEY = 'attempts_count ' ;
2222
23- protected $ declareExchange ;
24- protected $ declareQueue ;
25- protected $ declareBindQueue ;
2623 protected $ sleepOnError ;
2724
28- protected $ defaultQueue ;
29- protected $ queueParameters ;
30- protected $ queueArguments ;
31- protected $ configExchange ;
25+ protected $ queueOptions ;
26+ protected $ exchangeOptions ;
3227
3328 private $ declaredExchanges = [];
3429 private $ declaredQueues = [];
@@ -43,13 +38,12 @@ class RabbitMQQueue extends Queue implements QueueContract
4338 public function __construct (AmqpContext $ context , array $ config )
4439 {
4540 $ this ->context = $ context ;
46- $ this ->defaultQueue = $ config ['queue ' ];
47- $ this ->queueParameters = $ config ['queue_params ' ];
48- $ this ->queueArguments = isset ($ this ->queueParameters ['arguments ' ]) ? json_decode ($ this ->queueParameters ['arguments ' ], true ) : [];
49- $ this ->configExchange = $ config ['exchange_params ' ];
50- $ this ->declareExchange = $ config ['exchange_declare ' ];
51- $ this ->declareQueue = $ config ['queue_declare ' ];
52- $ this ->declareBindQueue = $ config ['queue_declare_bind ' ];
41+
42+ $ this ->queueOptions = $ config ['options ' ]['queue ' ];
43+ $ this ->queueOptions ['arguments ' ] = isset ($ this ->queueOptions ['arguments ' ]) ? json_decode ($ this ->queueOptions ['arguments ' ], true ) : [];
44+
45+ $ this ->exchangeOptions = $ config ['options ' ]['exchange ' ];
46+
5347 $ this ->sleepOnError = $ config ['sleep_on_error ' ] ?? 5 ;
5448 }
5549
@@ -177,49 +171,49 @@ public function getContext(): AmqpContext
177171 */
178172 private function declareEverything (string $ queueName = null ): array
179173 {
180- $ queueName = $ queueName ?: $ this ->defaultQueue ;
181- $ exchangeName = $ this ->configExchange ['name ' ] ?: $ queueName ;
174+ $ queueName = $ queueName ?: $ this ->queueOptions [ ' name ' ] ;
175+ $ exchangeName = $ this ->exchangeOptions ['name ' ] ?: $ queueName ;
182176
183177 $ topic = $ this ->context ->createTopic ($ exchangeName );
184- $ topic ->setType ($ this ->configExchange ['type ' ]);
185- if ($ this ->configExchange ['passive ' ]) {
178+ $ topic ->setType ($ this ->exchangeOptions ['type ' ]);
179+ if ($ this ->exchangeOptions ['passive ' ]) {
186180 $ topic ->addFlag (AmqpTopic::FLAG_PASSIVE );
187181 }
188- if ($ this ->configExchange ['durable ' ]) {
182+ if ($ this ->exchangeOptions ['durable ' ]) {
189183 $ topic ->addFlag (AmqpTopic::FLAG_DURABLE );
190184 }
191- if ($ this ->configExchange ['auto_delete ' ]) {
185+ if ($ this ->exchangeOptions ['auto_delete ' ]) {
192186 $ topic ->addFlag (AmqpTopic::FLAG_AUTODELETE );
193187 }
194188
195- if ($ this ->declareExchange && !in_array ($ exchangeName , $ this ->declaredExchanges , true )) {
189+ if ($ this ->exchangeOptions [ ' declare ' ] && !in_array ($ exchangeName , $ this ->declaredExchanges , true )) {
196190 $ this ->context ->declareTopic ($ topic );
197191
198192 $ this ->declaredExchanges [] = $ exchangeName ;
199193 }
200194
201195 $ queue = $ this ->context ->createQueue ($ queueName );
202- $ queue ->setArguments ($ this ->queueArguments );
203- if ($ this ->queueParameters ['passive ' ]) {
196+ $ queue ->setArguments ($ this ->queueOptions [ ' arguments ' ] );
197+ if ($ this ->queueOptions ['passive ' ]) {
204198 $ queue ->addFlag (AmqpQueue::FLAG_PASSIVE );
205199 }
206- if ($ this ->queueParameters ['durable ' ]) {
200+ if ($ this ->queueOptions ['durable ' ]) {
207201 $ queue ->addFlag (AmqpQueue::FLAG_DURABLE );
208202 }
209- if ($ this ->queueParameters ['exclusive ' ]) {
203+ if ($ this ->queueOptions ['exclusive ' ]) {
210204 $ queue ->addFlag (AmqpQueue::FLAG_EXCLUSIVE );
211205 }
212- if ($ this ->queueParameters ['auto_delete ' ]) {
206+ if ($ this ->queueOptions ['auto_delete ' ]) {
213207 $ queue ->addFlag (AmqpQueue::FLAG_AUTODELETE );
214208 }
215209
216- if ($ this ->declareQueue && !in_array ($ queueName , $ this ->declaredQueues , true )) {
210+ if ($ this ->queueOptions [ ' declare ' ] && !in_array ($ queueName , $ this ->declaredQueues , true )) {
217211 $ this ->context ->declareQueue ($ queue );
218212
219213 $ this ->declaredQueues [] = $ queueName ;
220214 }
221215
222- if ($ this ->declareBindQueue ) {
216+ if ($ this ->queueOptions [ ' bind ' ] ) {
223217 $ this ->context ->bind (new AmqpBind ($ queue , $ topic , $ queue ->getQueueName ()));
224218 }
225219
0 commit comments