use Symfony\Component\Messenger\EventListener\DispatchPcntlSignalListener;
use Symfony\Component\Messenger\EventListener\StopWorkerOnSignalsListener;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\Messenger\Worker;
use Symfony\Component\Serializer
as SerializerComponent;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
$serializer =
new Serializer( new SerializerComponent\
Serializer([new ObjectNormalizer(),
new ArrayDenormalizer()],
['json' =>
new JsonEncoder()]));
$connection = Connection::
fromDsn(getenv('DSN'
));
$receiver =
new AmqpReceiver($connection,
$serializer);
$eventDispatcher =
new EventDispatcher();
$eventDispatcher->
addSubscriber(new StopWorkerOnSignalsListener());
$eventDispatcher->
addSubscriber(new DispatchPcntlSignalListener());
$worker =
new Worker(['the_receiver' =>
$receiver],
new class() implements MessageBusInterface
{ public function dispatch($envelope, array
$stamps =
[]): Envelope
{