sroze / messenger-enqueue-transport

Uses Enqueue with Symfony's Messenger component.
MIT License
191 stars 55 forks source link

Option to send to queue when used as `framework:sender` #118

Open RafaelKr opened 2 years ago

RafaelKr commented 2 years ago

I have the following config/packages/messenger.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:framework="http://symfony.com/schema/dic/symfony"
           xsi:schemaLocation="http://symfony.com/schema/dic/services
        https://symfony.com/schema/dic/services/services-1.0.xsd
        http://symfony.com/schema/dic/symfony
        https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

    <framework:config>
        <framework:messenger>
            <framework:routing message-class="Vcore\MyBundle\Messenger\MyMessage">
                <framework:sender service="activemq_sender"/>
            </framework:routing>

            <framework:transport
                name="activemq_sender"
                dsn="enqueue://my_activemq?queue[name]=MyQueue"
                serializer="Vcore\MyBundle\Messenger\MySerializer"
            />
        </framework:messenger>
    </framework:config>
</container>

So whenever I dispatch Vcore\MyBundle\Messenger\MyMessage it will be sent to ActiveMQ. As you can see from the configuration I would like to send to a queue, but the messenger-enqueue-transport will always send to a topic.

https://github.com/sroze/messenger-enqueue-transport/blob/83c30ede78a0ef5cc890d1ecab7a110d3e1c2aef/QueueInteropTransport.php#L126-L135

Could we implement that it will automatically use a queue if only the queue[name] option is configured?

RafaelKr commented 2 years ago

BTW for everyone else stumbling on this I'm now working around it with service decoration. I copied the QueueInteropTransport.php to a DecoratingQueueInteropTransport.php inside my bundle and replaced Topic with Queue. Also I copied the QueueInteropTransportFactory.php to DecoratingQueueInteropTransportFactory.php and in createTransport I return a DecoratingQueueInteropTransport instance.