Skip to content

Commit d08f681

Browse files
committed
Merge branch '4.4'
* 4.4: [Messenger] `get()` usage
2 parents 86d2c25 + b607ee3 commit d08f681

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

components/messenger.rst

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ do is to write your own CSV receiver::
264264

265265
use App\Message\NewOrder;
266266
use Symfony\Component\Messenger\Envelope;
267+
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
267268
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
268269
use Symfony\Component\Serializer\SerializerInterface;
269270

@@ -280,17 +281,23 @@ do is to write your own CSV receiver::
280281

281282
public function get(): iterable
282283
{
283-
$ordersFromCsv = $this->serializer->deserialize(file_get_contents($this->filePath), 'csv');
284-
285-
foreach ($ordersFromCsv as $orderFromCsv) {
286-
$order = new NewOrder($orderFromCsv['id'], $orderFromCsv['account_id'], $orderFromCsv['amount']);
287-
288-
$envelope = new Envelope($order);
284+
// Receive the envelope according to your transport ($yourEnvelope here),
285+
// in most cases, using a connection is the easiest solution.
286+
if (null === $yourEnvelope) {
287+
return [];
288+
}
289289

290-
$handler($envelope);
290+
try {
291+
$envelope = $this->serializer->decode([
292+
'body' => $yourEnvelope['body'],
293+
'headers' => $yourEnvelope['headers'],
294+
]);
295+
} catch (MessageDecodingFailedException $exception) {
296+
$this->connection->reject($yourEnvelope['id']);
297+
throw $exception;
291298
}
292299

293-
return [$envelope];
300+
return [$envelope->with(new CustomStamp($yourEnvelope['id']);
294301
}
295302

296303
public function ack(Envelope $envelope): void
@@ -300,7 +307,8 @@ do is to write your own CSV receiver::
300307

301308
public function reject(Envelope $envelope): void
302309
{
303-
// Reject the message if needed
310+
// In the case of a custom connection
311+
$this->connection->reject($this->findCustomStamp($envelope)->getId());
304312
}
305313
}
306314

0 commit comments

Comments
 (0)