I use Messenger Component in a non-Symfony project and Doctrine as a DSN transport. Now I want to test my code and consume the messages on my local machine, but I don't know how to run the messenger command in the console.
I tried to use Symfony\Component\Console\Application
and register the \Symfony\Component\Messenger\Command\ConsumeMessagesCommand
command in the console but there are many nested dependencies.
Do you have any idea?
We actually do this in many projects, even WordPress CLI tools, and we use this library to do it along with this for the transport. It doesn't require Symfony and can work with most queue systems that follow the general standard.
The general idea is that you want something (probably a singleton) to return an instance of
Interop\Queue\Context
, and here's what we use:You'll also want something to handle each message, and you'll want to pass the message and consumer to it:
Then to use it:
Sprinkle a lot of try/catch around that, too, and make sure that no matter what you acknowledge or fail the message in some way.