Description
Symfony version(s) affected: master (4.3)
Description
When creating a handler that implements MessageSubscriberInterface
, which passes custom options about the handler (e.g. from_transport
from #30958), if the user changes those options, they are not visible in the app. The problem is that this input is used to create an internal service (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php#L168), but the files these options were sourced from (the handler itself) is not added as a container resource.
How to reproduce
namespace App\MessageHandler;
use App\Message\SendEmail;
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
class SendEmailHandler implements MessageSubscriberInterface
{
public function __invoke(SendEmail $email)
{
//
}
public static function getHandledMessages(): iterable
{
yield SendEmail::class => [
'from_transport' => 'async',
];
}
}
Completely clear the cache. You can see that this handler is only called when coming from some async
transport. Now, change to some other transport name and try again. It will still try to consume only from the original, async
transport.
Possible Solution
If the config comes from the handler (i.e. if it implements MessageSubscriberInterface
), it should be added as a resource. Doesn't this also affect normal MessageHandlerInterface
handlers - if you changed the type-hint to __invoke()
, would that cause a container rebuild?