ssi-anik / amqp

php-amqplib wrapper that eases the consumption of RabbitMQ. A painless way of using RabbitMQ
https://packagist.org/packages/anik/amqp
MIT License
134 stars 23 forks source link

Queues are not being declared dynamically during publishing #8

Closed zMeadz closed 4 years ago

zMeadz commented 4 years ago

Firstly, great work on the package and your detailed documentation.

Having an issue when publishing a message. Rabbit receives the message, the Exchange is declared / created, but the queue is not, and the message goes no where.

app('amqp')->publish('message', 'routing-key', [
        'exchange' => [
           'declare' => true,
           'name' => 'my_exchange',
           'type' => 'direct',
           'durable' => true,
           'auto_delete' => false,
           'internal' => false,
        ],
        'queue' => [
               'name' => 'queue_name',
               'declare' => true,
               'durable' => true,
               'auto_delete' => false,
               'd_properties' => [
                       'name' => 'queue_name,
                       'durable' => true,
                       'auto_delete' => false,
                ],
               'b_properties' => [
                       'source' => 'my_exchange',
                       'destination' => 'queue_name',
                       'destination_type' => 'queue',
                       'routing_key' => 'routing-key',
                ]
         ],
]);

Thanks in advance for taking a look.

ssi-anik commented 4 years ago

@zMeadz, I am extremely sorry to reply to you this late. What I can see is you're just trying to publish a message. When publishing messages, the queue is not required. That's why the queue is not created. But if you try to consume a message, then the messages will be on the queue from that exchange. That's why it'll try to create the exchange and queue. But in your scenario, it'll try to create the exchange not the queue.

So, if you want your queues to be created, you need to fire up the listeners first, and then publish messages. I hope it solves your problem. Finally, thanks for your appreciation. <3

zMeadz commented 4 years ago

Thanks for getting back. For this use case, my consumer is in a separate application. Perhaps best practice is to declare the queue and routing key from that consumer. Nevertheless, the documentation here and config example led me to believe that it could be declared on the producer's end.

I ended up using the base AMQP library to accomplish this, and it could be a fairly easy addition to the project if it comes up again. Thanks again for your input.