19
19
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
20
20
use Symfony \Component \Console \Output \OutputInterface ;
21
21
use Symfony \Component \Console \Style \SymfonyStyle ;
22
+ use Symfony \Component \DependencyInjection \ServiceLocator ;
22
23
use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
23
24
use Symfony \Component \Messenger \Event \WorkerMessageReceivedEvent ;
24
25
use Symfony \Component \Messenger \EventListener \StopWorkerOnMessageLimitListener ;
@@ -39,14 +40,15 @@ class FailedMessagesRetryCommand extends AbstractFailedMessagesCommand
39
40
private $ eventDispatcher ;
40
41
private $ messageBus ;
41
42
private $ logger ;
43
+ private $ failedTransportsByName ;
42
44
43
- public function __construct (string $ receiverName , ReceiverInterface $ receiver , MessageBusInterface $ messageBus , EventDispatcherInterface $ eventDispatcher , LoggerInterface $ logger = null )
45
+ public function __construct (string $ receiverName , ReceiverInterface $ receiver , MessageBusInterface $ messageBus , EventDispatcherInterface $ eventDispatcher , LoggerInterface $ logger = null , ServiceLocator $ failedTransportsByName )
44
46
{
45
47
$ this ->eventDispatcher = $ eventDispatcher ;
46
48
$ this ->messageBus = $ messageBus ;
47
49
$ this ->logger = $ logger ;
48
50
49
- parent ::__construct ($ receiverName , $ receiver );
51
+ parent ::__construct ($ receiverName , $ receiver, $ failedTransportsByName );
50
52
}
51
53
52
54
/**
@@ -56,6 +58,7 @@ protected function configure(): void
56
58
{
57
59
$ this
58
60
->setDefinition ([
61
+ new InputArgument ('failed-transport ' , InputArgument::REQUIRED , 'failed transport name ' ),
59
62
new InputArgument ('id ' , InputArgument::IS_ARRAY , 'Specific message id(s) to retry ' ),
60
63
new InputOption ('force ' , null , InputOption::VALUE_NONE , 'Force action without confirmation ' ),
61
64
])
@@ -95,10 +98,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
95
98
$ io ->comment ('Re-run the command with a -vv option to see logs about consumed messages. ' );
96
99
}
97
100
98
- $ receiver = $ this ->getReceiver ();
101
+ $ failedTransport = $ input ->getArgument ('failed-transport ' );
102
+ $ receiver = $ this ->getReceiver ($ failedTransport );
99
103
$ this ->printPendingMessagesMessage ($ receiver , $ io );
100
104
101
- $ io ->writeln (sprintf ('To retry all the messages, run <comment>messenger:consume %s</comment> ' , $ this ->getReceiverName ()));
105
+ $ io ->writeln (sprintf ('To retry all the messages, run <comment>messenger:consume %s</comment> ' , $ this ->getReceiverName ($ failedTransport )));
102
106
103
107
$ shouldForce = $ input ->getOption ('force ' );
104
108
$ ids = $ input ->getArgument ('id ' );
@@ -107,20 +111,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
107
111
throw new RuntimeException ('Message id must be passed when in non-interactive mode. ' );
108
112
}
109
113
110
- $ this ->runInteractive ($ io , $ shouldForce );
114
+ $ this ->runInteractive ($ failedTransport , $ io , $ shouldForce );
111
115
112
116
return 0 ;
113
117
}
114
118
115
- $ this ->retrySpecificIds ($ ids , $ io , $ shouldForce );
119
+ $ this ->retrySpecificIds ($ failedTransport , $ ids , $ io , $ shouldForce );
116
120
$ io ->success ('All done! ' );
117
121
118
122
return 0 ;
119
123
}
120
124
121
- private function runInteractive (SymfonyStyle $ io , bool $ shouldForce )
125
+ private function runInteractive (string $ failedTransport , SymfonyStyle $ io , bool $ shouldForce )
122
126
{
123
- $ receiver = $ this ->getReceiver ();
127
+ $ receiver = $ this ->getReceiver ($ failedTransport );
124
128
$ count = 0 ;
125
129
if ($ receiver instanceof ListableReceiverInterface) {
126
130
// for listable receivers, find the messages one-by-one
@@ -135,7 +139,7 @@ private function runInteractive(SymfonyStyle $io, bool $shouldForce)
135
139
136
140
$ id = $ this ->getMessageId ($ envelope );
137
141
if (null === $ id ) {
138
- throw new LogicException (sprintf ('The "%s" receiver is able to list messages by id but the envelope is missing the TransportMessageIdStamp stamp. ' , $ this ->getReceiverName ()));
142
+ throw new LogicException (sprintf ('The "%s" receiver is able to list messages by id but the envelope is missing the TransportMessageIdStamp stamp. ' , $ this ->getReceiverName ($ failedTransport )));
139
143
}
140
144
$ ids [] = $ id ;
141
145
}
@@ -145,11 +149,11 @@ private function runInteractive(SymfonyStyle $io, bool $shouldForce)
145
149
break ;
146
150
}
147
151
148
- $ this ->retrySpecificIds ($ ids , $ io , $ shouldForce );
152
+ $ this ->retrySpecificIds ($ failedTransport , $ ids , $ io , $ shouldForce );
149
153
}
150
154
} else {
151
155
// get() and ask messages one-by-one
152
- $ count = $ this ->runWorker ($ this ->getReceiver (), $ io , $ shouldForce );
156
+ $ count = $ this ->runWorker ($ this ->getReceiver ($ failedTransport ), $ io , $ shouldForce );
153
157
}
154
158
155
159
// avoid success message if nothing was processed
@@ -158,7 +162,7 @@ private function runInteractive(SymfonyStyle $io, bool $shouldForce)
158
162
}
159
163
}
160
164
161
- private function runWorker (ReceiverInterface $ receiver , SymfonyStyle $ io , bool $ shouldForce ): int
165
+ private function runWorker (string $ failedTransport , ReceiverInterface $ receiver , SymfonyStyle $ io , bool $ shouldForce ): int
162
166
{
163
167
$ count = 0 ;
164
168
$ listener = function (WorkerMessageReceivedEvent $ messageReceivedEvent ) use ($ io , $ receiver , $ shouldForce , &$ count ) {
@@ -179,7 +183,7 @@ private function runWorker(ReceiverInterface $receiver, SymfonyStyle $io, bool $
179
183
$ this ->eventDispatcher ->addListener (WorkerMessageReceivedEvent::class, $ listener );
180
184
181
185
$ worker = new Worker (
182
- [$ this ->getReceiverName () => $ receiver ],
186
+ [$ this ->getReceiverName ($ failedTransport ) => $ receiver ],
183
187
$ this ->messageBus ,
184
188
$ this ->eventDispatcher ,
185
189
$ this ->logger
@@ -194,12 +198,12 @@ private function runWorker(ReceiverInterface $receiver, SymfonyStyle $io, bool $
194
198
return $ count ;
195
199
}
196
200
197
- private function retrySpecificIds (array $ ids , SymfonyStyle $ io , bool $ shouldForce )
201
+ private function retrySpecificIds (string $ failedTransport , array $ ids , SymfonyStyle $ io , bool $ shouldForce )
198
202
{
199
- $ receiver = $ this ->getReceiver ();
203
+ $ receiver = $ this ->getReceiver ($ failedTransport );
200
204
201
205
if (!$ receiver instanceof ListableReceiverInterface) {
202
- throw new RuntimeException (sprintf ('The "%s" receiver does not support retrying messages by id. ' , $ this ->getReceiverName ()));
206
+ throw new RuntimeException (sprintf ('The "%s" receiver does not support retrying messages by id. ' , $ this ->getReceiverName ($ failedTransport )));
203
207
}
204
208
205
209
foreach ($ ids as $ id ) {
@@ -209,7 +213,7 @@ private function retrySpecificIds(array $ids, SymfonyStyle $io, bool $shouldForc
209
213
}
210
214
211
215
$ singleReceiver = new SingleMessageReceiver ($ receiver , $ envelope );
212
- $ this ->runWorker ($ singleReceiver , $ io , $ shouldForce );
216
+ $ this ->runWorker ($ failedTransport , $ singleReceiver , $ io , $ shouldForce );
213
217
}
214
218
}
215
219
}
0 commit comments