Answer the question
In order to leave comments, you need to log in
Why are entities processed in Symfony Messenger not flushed?
Hello. I'm having a problem while working with queues in symphony. Queues use the Symfony Messenger + RabbitMQ bundle.
Essence of the question:
bus:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
serializer: messenger.transport.symfony_serializer
options:
exchange:
name: bus
type: direct
default_publish_routing_key: create
queues:
create:
binding_keys: [ create ]
update:
binding_keys: [ update ]
class DoctrineEntityManagerClearMiddleware implements MiddlewareInterface
{
private ManagerRegistry $managerRegistry;
private ?string $entityManagerName;
public function __construct(ManagerRegistry $managerRegistry, string $entityManagerName = null)
{
$this->managerRegistry = $managerRegistry;
$this->entityManagerName = $entityManagerName;
}
public function handle(Envelope $envelope, StackInterface $stack): Envelope
{
try {
$entityManager = $this->managerRegistry->getManager($this->entityManagerName);
} catch (\InvalidArgumentException $e) {
throw new UnrecoverableMessageHandlingException($e->getMessage(), 0, $e);
}
$entityManager->clear();
return $stack->next()->handle($envelope, $stack);
}
}
buses:
command.bus:
middleware:
- doctrine_ping_connection
- doctrine_close_connection
- 'App\Middleware\DoctrineEntityManagerClearMiddleware'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question