@@ -123,51 +123,42 @@ protected function processExtensions(array &$config): void
123123 continue ;
124124 }
125125
126- $ exchangeRetry = $ name . '.dlx-retry ' ;
127- $ exchangeDlx = $ name . '.dlx-wait ' ;
126+ $ exchangeOut = $ name . '.dlx-out ' ;
127+ $ exchangeIn = $ name . '.dlx-in ' ;
128+
129+ $ queueDlx = sprintf ('%s.dlx-%s ' , $ name , (string ) $ data ['dlx ' ]);
130+
131+ # Setup dead letter exchange
132+ $ config ['queues ' ][$ name ]['arguments ' ]['x-dead-letter-exchange ' ] = $ exchangeIn ;
128133
129134 # DLX Exchange: will pass msg to queue
130- $ config ['exchanges ' ][$ exchangeRetry ] = $ this ->exchangesHelper ->processConfiguration ([
135+ $ config ['exchanges ' ][$ exchangeOut ] = $ this ->exchangesHelper ->processConfiguration ([
131136 'connection ' => $ data ['connection ' ],
132137 'type ' => ExchangesHelper::ExchangeTypes[3 ],
133138 'queueBindings ' => [
134- $ name => [
135- 'routingKey ' => [],
136- ],
139+ $ name => [],
137140 ],
138141 ]);
139142
140143 # DLX Exchange: will pass msg to dlx queue
141- $ exchangeDataBag = [
144+ $ config [ ' exchanges ' ][ $ exchangeIn ] = $ this -> exchangesHelper -> processConfiguration ( [
142145 'connection ' => $ data ['connection ' ],
143- 'type ' => ExchangesHelper::ExchangeTypes[2 ], // headers
144- 'queueBindings ' => []
145- ];
146+ 'type ' => ExchangesHelper::ExchangeTypes[3 ],
147+ 'queueBindings ' => [
148+ $ queueDlx => []
149+ ]
150+ ]);
146151
147152 # Expand dlx into new queues and exchange for them
148- foreach ($ data ['dlx ' ] as $ pos => $ seconds ) {
149- $ queueName = sprintf ('%s.dlx-%s ' , $ name , (string ) $ seconds );
150- $ config ['queues ' ][$ queueName ] = $ this ->queuesHelper ->processConfiguration ([
151- 'connection ' => $ data ['connection ' ],
152- 'autoCreate ' => true ,
153- 'arguments ' => [
154- 'x-dead-letter-exchange ' => $ exchangeRetry ,
155- 'x-message-ttl ' => $ seconds * 1000 ,
156- ]
157- ]);
158-
159- $ exchangeDataBag ['queueBindings ' ][$ queueName ] = [
160- 'arguments ' => [
161- 'x-match ' => 'all ' ,
162- 'x-death ' => [
163- 'name ' => $ name ,
164- 'count ' => $ pos * 2 ,
165- ],
166- ],
167- ];
168- }
153+ $ config ['queues ' ][$ queueDlx ] = $ this ->queuesHelper ->processConfiguration ([
154+ 'connection ' => $ data ['connection ' ],
155+ 'autoCreate ' => true ,
156+ 'arguments ' => [
157+ 'x-dead-letter-exchange ' => $ exchangeOut ,
158+ 'x-message-ttl ' => $ data ['dlx ' ] * 1000 ,
159+ ]
160+ ]);
169161
170- $ config ['exchanges ' ][$ exchangeDlx ] = $ this ->exchangesHelper ->processConfiguration ($ exchangeDataBag );
171162 unset($ config ['queues ' ][$ name ]['dlx ' ]);
172163 }
173164 }
0 commit comments