8000 [Messenger] Add a way to redispatch a message by fabpot · Pull Request #49734 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Add a way to redispatch a message #49734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Messenger] Add a way to redispatch a message
  • Loading branch information
fabpot committed Mar 19, 2023
commit 4c1dcfa591bcc48105bfd806ec8fdd2f3fa1dfeb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\Messenger\EventListener\StopWorkerOnCustomStopExceptionListener;
use Symfony\Component\Messenger\EventListener\StopWorkerOnRestartSignalListener;
use Symfony\Component\Messenger\EventListener\StopWorkerOnSignalsListener;
use Symfony\Component\Messenger\Handler\RedispatchMessageHandler;
use Symfony\Component\Messenger\Middleware\AddBusNameStampMiddleware;
use Symfony\Component\Messenger\Middleware\DispatchAfterCurrentBusMiddleware;
use Symfony\Component\Messenger\Middleware\FailedMessageProcessingMiddleware;
Expand Down Expand Up @@ -219,5 +220,11 @@
abstract_arg('message bus locator'),
service('messenger.default_bus'),
])

->set('messenger.redispatch_message_handler', RedispatchMessageHandler::class)
->args([
service('messenger.default_bus'),
])
->tag('messenger.message_handler')
;
};
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CHANGELOG
* Deprecate `StopWorkerOnSigtermSignalListener` in favor of
`StopWorkerOnSignalsListener` and make it configurable with SIGINT and
SIGTERM by default
* Add `RedispatchMessage` and `RedispatchMessageHandler`

6.2
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Messenger\Handler;

use Symfony\Component\Messenger\Message\RedispatchMessage;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\TransportNamesStamp;

final class RedispatchMessageHandler
{
public function __construct(
private MessageBusInterface $bus,
) {
}

public function __invoke(RedispatchMessage $message)
{
$this->bus->dispatch($message->envelope, [new TransportNamesStamp($message->transportNames)]);
}
}
30 changes: 30 additions & 0 deletions src/Symfony/Component/Messenger/Message/RedispatchMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Messenger\Message;

use Symfony\Component\Messenger\Envelope;

/**
* @internal
*/
final class RedispatchMessage
{
/**
* @param object|Envelope $message The message or the message pre-wrapped in an envelope
* @param string[]|string $transportNames Transport names to be used for the message
*/
public function __construct(
public readonly object $envelope,
public readonly array|string $transportNames = [],
) {
}
}
0