@@ -270,6 +270,7 @@ do is to write your own CSV receiver::
270
270
271
271
use App\Message\NewOrder;
272
272
use Symfony\Component\Messenger\Envelope;
273
+ use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
273
274
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
274
275
use Symfony\Component\Serializer\SerializerInterface;
275
276
@@ -286,17 +287,23 @@ do is to write your own CSV receiver::
286
287
287
288
public function get(): iterable
288
289
{
289
- $ordersFromCsv = $this->serializer->deserialize(file_get_contents($this->filePath), 'csv');
290
-
291
- foreach ($ordersFromCsv as $orderFromCsv) {
292
- $order = new NewOrder($orderFromCsv['id'], $orderFromCsv['account_id'], $orderFromCsv['amount']);
293
-
294
- $envelope = new Envelope($order);
290
+ // Receive the envelope according to your transport ($yourEnvelope here),
291
+ // in most cases, using a connection is the easiest solution.
292
+ if (null === $yourEnvelope) {
293
+ return [];
294
+ }
295
295
296
- $handler($envelope);
296
+ try {
297
+ $envelope = $this->serializer->decode([
298
+ 'body' => $yourEnvelope['body'],
299
+ 'headers' => $yourEnvelope['headers'],
300
+ ]);
301
+ } catch (MessageDecodingFailedException $exception) {
302
+ $this->connection->reject($yourEnvelope['id']);
303
+ throw $exception;
297
304
}
298
305
299
- return [$envelope] ;
306
+ return [$envelope->with(new CustomStamp($yourEnvelope['id']) ;
300
307
}
301
308
302
309
public function ack(Envelope $envelope): void
@@ -306,7 +313,8 @@ do is to write your own CSV receiver::
306
313
307
314
public function reject(Envelope $envelope): void
308
315
{
309
- // Reject the message if needed
316
+ // In the case of a custom connection
317
+ $this->connection->reject($this->findCustomStamp($envelope)->getId());
310
318
}
311
319
}
312
320
0 commit comments