@@ -123,51 +123,42 @@ protected function processExtensions(array &$config): void
123
123
continue ;
124
124
}
125
125
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 ;
128
133
129
134
# DLX Exchange: will pass msg to queue
130
- $ config ['exchanges ' ][$ exchangeRetry ] = $ this ->exchangesHelper ->processConfiguration ([
135
+ $ config ['exchanges ' ][$ exchangeOut ] = $ this ->exchangesHelper ->processConfiguration ([
131
136
'connection ' => $ data ['connection ' ],
132
137
'type ' => ExchangesHelper::ExchangeTypes[3 ],
133
138
'queueBindings ' => [
134
- $ name => [
135
- 'routingKey ' => [],
136
- ],
139
+ $ name => [],
137
140
],
138
141
]);
139
142
140
143
# DLX Exchange: will pass msg to dlx queue
141
- $ exchangeDataBag = [
144
+ $ config [ ' exchanges ' ][ $ exchangeIn ] = $ this -> exchangesHelper -> processConfiguration ( [
142
145
'connection ' => $ data ['connection ' ],
143
- 'type ' => ExchangesHelper::ExchangeTypes[2 ], // headers
144
- 'queueBindings ' => []
145
- ];
146
+ 'type ' => ExchangesHelper::ExchangeTypes[3 ],
147
+ 'queueBindings ' => [
148
+ $ queueDlx => []
149
+ ]
150
+ ]);
146
151
147
152
# 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
+ ]);
169
161
170
- $ config ['exchanges ' ][$ exchangeDlx ] = $ this ->exchangesHelper ->processConfiguration ($ exchangeDataBag );
171
162
unset($ config ['queues ' ][$ name ]['dlx ' ]);
172
163
}
173
164
}
0 commit comments