Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Symfony Messenger - Subscribing multiple Handlers to Messages
namespace Acme\TemporaryWork\Infrastructure\ProcessManager;
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
use Prooph\EventSourcing\AggregateChanged;
use Acme\TemporaryWork\Domain\Model\Agency\Event\AgencyHired;
use Acme\TemporaryWork\Domain\Model\Agency\Event\AgencyModified;
use Acme\PersonnelManagement\Infrastructure\RabbitMq\Producer;
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
final class AgencyPublisher extends Producer
implements MessageSubscriberInterface
public function __construct(ProducerInterface $producer)
$this->producer = $producer;
public function __invoke(AggregateChanged $event): void
$data = array_merge(
['agencyId' => $event->agencyId()->toString()],
switch (get_class($event)) {
case AgencyHired::class:
$this->publish($data, '');
case AgencyModified::class:
$this->publish($data, '');
public static function getHandledMessages(): iterable
yield AgencyHired::class;
yield AgencyModified::class;
Copy link

webdevilopers commented Jun 6, 2020

Is there a way to subscribe a symfony messenger message to multiple handlers without adding code to the class via MessageSubscriberInterface - maybe via config?

Came from:

/cc @weaverryan

Tutorial by @knpuniversity:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment