bschmitt / laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages
MIT License
268 stars 86 forks source link

Publisher and Consumer should not be singletons #95

Open Cellard opened 3 years ago

Cellard commented 3 years ago

If you publish first message:

Amqp::publish('task_share', $payload, [
   'exchange_type' => 'fanout',
   'exchange' => 'shared'
]);

And then publish second message:

Amqp::publish('image', $payload, [
   'queue' => 'tasks'
]);

The second message goes not in tasks queue but in shared exchange. It happens because Publisher bases on properties left from previous message.

Library should either instantiate new Publisher each time or reset properties to its default state.

I expect the Consumer meets the same problem.


Programmer may escape the problem with providing full config to every publish. But this is extremely unclear behaviour. I think it is better to patch the library.

stevenklar commented 3 years ago

Hi @Cellard

I think you are totally right. This is a bad side effect. @bschmitt What do you think?

Thanks for your feedback. -Steven

bschmitt commented 3 years ago

Agree. I'm happy to merge in case s/o provides a PR. Thanks!