Fixing failure transport for symfony/messenger 6.2

This commit is contained in:
Ferdinand Kuhl 2023-01-05 15:33:20 +01:00
parent 724aaca9f8
commit ed4cf1b39a
3 changed files with 52 additions and 5 deletions

View file

@ -0,0 +1,33 @@
<?php
namespace DigiComp\FlowSymfonyBridge\Messenger\Transport;
use Neos\Flow\Annotations as Flow;
use Psr\Container\ContainerInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
/**
* @Flow\Scope("singleton")
*/
class FailureTransportContainer implements ContainerInterface
{
/**
* @var TransportInterface[]
*/
protected array $transports;
public function get(string $id)
{
return $this->transports[$id];
}
public function has(string $id)
{
return isset($this->transports[$id]);
}
public function set(string $id, TransportInterface $transport)
{
$this->transports[$id] = $transport;
}
}

View file

@ -31,6 +31,12 @@ class TransportsContainer implements ContainerInterface
*/ */
protected $transportFactory; protected $transportFactory;
/**
* @Flow\Inject
* @var FailureTransportContainer
*/
protected $failureTransports;
/** /**
* @var TransportInterface[] * @var TransportInterface[]
*/ */
@ -65,6 +71,11 @@ class TransportsContainer implements ContainerInterface
$transportDefinition['options'], $transportDefinition['options'],
$this->objectManager->get($transportDefinition['serializer']) $this->objectManager->get($transportDefinition['serializer'])
); );
if (isset($transportDefinition['failureTransport'])) {
$this->failureTransports->set($id, $this->get($transportDefinition['failureTransport']));
} elseif (isset($this->configuration['failureTransport'])) {
$this->failureTransports->set($id, $this->get($this->configuration['failureTransport']));
}
} }
return $this->transports[$id]; return $this->transports[$id];
} }

View file

@ -89,6 +89,13 @@ DigiComp.FlowSymfonyBridge.Messenger:ReceiversContainer:
object: 'DigiComp\FlowSymfonyBridge\Messenger\Transport\TransportsContainer' object: 'DigiComp\FlowSymfonyBridge\Messenger\Transport\TransportsContainer'
# TODO: add own receivers here, which are no transports # TODO: add own receivers here, which are no transports
DigiComp.FlowSymfonyBridge.Messenger:FailureSenderContainer:
className: 'DigiComp\FlowSymfonyBridge\Messenger\ObjectManagement\ChainedContainer'
scope: 'singleton'
arguments:
1:
object: 'DigiComp\FlowSymfonyBridge\Messenger\Transport\FailureTransportContainer'
DigiComp.FlowSymfonyBridge.Messenger:EventDispatcher: DigiComp.FlowSymfonyBridge.Messenger:EventDispatcher:
className: 'Symfony\Component\EventDispatcher\EventDispatcher' className: 'Symfony\Component\EventDispatcher\EventDispatcher'
scope: 'singleton' scope: 'singleton'
@ -133,10 +140,6 @@ Symfony\Component\Messenger\EventListener\SendFailedMessageToFailureTransportLis
arguments: arguments:
1: 1:
object: object:
factoryObjectName: 'DigiComp.FlowSymfonyBridge.Messenger:SendersContainer' name: 'DigiComp.FlowSymfonyBridge.Messenger:FailureSenderContainer'
factoryMethodName: 'get'
arguments:
1:
setting: 'DigiComp.FlowSymfonyBridge.Messenger.failureTransport'
2: 2:
object: 'Psr\Log\LoggerInterface' object: 'Psr\Log\LoggerInterface'