bschmitt / laravel-amqp

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

Use multiple RabbitMQ instances #68

Open thureos opened 5 years ago

thureos commented 5 years ago

Hi,

First of all, thanks for this amazing library. Second, I would like to know how to configure 2 separate instances?

I kinda know how to do it in the config file but not while using it, you know like when you need to use multiple db instances.

$users = DB::connection('foo')->select(...);

Thanks,

bzrncev commented 4 years ago

Hi,

There is no function 'connection', but you can use the third parameter in publish or consume.

\Amqp::consume('some-queue', function ($message, $resolver) { }, config('amqp')['properties']['YOUR_CONNECTION'])
stevenklar commented 4 years ago

Right now this library support to define multiple connections but you can only use one. (use in config)

@bzrncev interesting workarround :) I will not close this issue in favor for discussion on if and how this could be implemented. Thank you for this suggestion.

weblogics commented 4 years ago

@bzrncev We are trying to use this approach for publish, but we're running into issues where the message is sent to both the default queue configured in settings as well as the requested queue sent along with the publish method.

This doesn't work

Amqp::publish('', $data, ['queue' => $queueName]);

This publishes to the default Queue in settings as well as the inserted $queueName

This kinda work's

Amqp::publish('EmailNotification', $data, ['queue' => $queueName]);

This causes knock-on effects with other services having to then be restarted in a particular way, any ideas why this occurs as we just want to use one connection, have a default Queue, but be able to independently publish to a separate Queue without populating to the default Queue within the settings file.

michail1982 commented 1 year ago

Hi, multiple instances can be placed in dfferent hosts, so need to be separated in https://github.com/bschmitt/laravel-amqp/blob/master/src/Request.php#L33

For first publish make connect , and rewrite host/port does not applied for next calls

like a sollution i sugget make hash from connection params and store/get connection from connections array by it