Bridge with symfony/messenger

Refer to the official documentation on Symfony’s website.

This bridge provides a way launch job using message bus.
Along with ways to interact with messenger inside jobs.

Launch Job through Messenger dispatcher

The DispatchMessageJobLauncher execute jobs via a symfony command message dispatch.

A LaunchJobMessage message will be dispatched and handled by the LaunchJobMessageHandler will be called with that message after being routed.

How to configure an async transport for the launcher?

You first need to configure an async transport, like explained in Symfony’s doc.

Then you will have to route the message to this async transport you created, like explained in Symfony’s doc.

You will end with something like:

# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async: "%env(MESSENGER_TRANSPORT_DSN)%"
        routing:
            'Yokai\Batch\Bridge\Symfony\Messenger\LaunchJobMessage':  async

Dispatch item with messenger writer

This item writer will dispatches each item through Symfony’s messenger bus.
Items must be objects that messenger can handle.
<?php

declare(strict_types=1);

use Symfony\Component\Messenger\MessageBusInterface;
use Yokai\Batch\Bridge\Symfony\Messenger\Writer\DispatchEachItemAsMessageWriter;

/** @var MessageBusInterface $messageBus */

new DispatchEachItemAsMessageWriter(
    messageBus: $messageBus,
);