Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[watermill-amqp] construct subscriptions using a single AMQP connection #182

Closed
ferbs opened this issue Apr 8, 2020 · 6 comments
Closed
Labels
enhancement New feature or request module: subscriber

Comments

@ferbs
Copy link

ferbs commented Apr 8, 2020

At present, amqp/subscriber.go establishes a new AMQP connection each time a Subscriber is instantiated. RabbitMQ recommends sharing a single connection. The AMQP connection is heavy, consuming ~ 100 KB of RAM each on the RabbitMQ side and slow to establish. (Citation.)

Ideally, Watermill's amqp.NewSubscriber method would automatically reuse a single connection, creating instead a new Channel. If this isn't feasible, please consider adding a new method that accepts an existing *amqp.Connection parameter (vs the current amqp.Config param.)

It's worth mentioning, the above might require updating reconnect logic, to manage the case of concurrent reconnect attempts by multiple subscribers sharing the same connection.

@jawr
Copy link

jawr commented May 7, 2020

An extension of this would mean we could remove/stop router handlers dynamically. At the moment the Handler shutdown process attempts to close the subscriber, which if shared would be undesired.

@raqbit
Copy link

raqbit commented Jul 3, 2020

Ideally, Watermill's amqp.NewSubscriber method would automatically reuse a single connection, creating instead a new Channel

The same could apply to publishers as well. For instance I'm working on a "processor" of sorts which acts on messages in one queue and outputs new messages to an output queue via a publisher. Currently watermill would create two connections, one for the subscriber and one for the publisher.

If this isn't feasible, please consider adding a new method that accepts an existing *amqp.Connection parameter (vs the current amqp.Config param.)

In this case you'd lose all benefits of having watermill take care of connection management for you. I think it'd be better if watermill somehow exposed the internal connection manager and allowed us to re-use that instead.

Another thing I noticed while looking at watermill's AMQP package is that an AMQP channel is created for each publish, which also isn't recommended. (Citation.)

In an ideal world the AMQP connection should be created once (unless you need multiple configs), the subscriber channel should be created once (per subscriber) & be long-lived and the same goes for the publisher channel.

@roblaszczak
Copy link
Member

Hello, I will be happy to merge any changes that are working and not affecting current functionality and flexibility :)

Feel free to experiment, with current tests It should be pretty simple. If you need any help, please hit me on Gophers slack so I can help. To make it easier, I shared some tribal knowledge about how I do debugging of the tests here: https://watermill.io/docs/troubleshooting/#debugging-pub-sub-tests

@bstasyszyn
Copy link

I have a pull request open that (hopefully) resolves this issue: ThreeDotsLabs/watermill-amqp#9. Please review. Thx! @roblaszczak @ferbs @jawr @raqbit

@ferbs
Copy link
Author

ferbs commented Nov 2, 2021

@bstasyszyn I've switched off the project using watermill-amqp so will go silent (leaving this issue open.)

@bstasyszyn
Copy link

PR was merged: ThreeDotsLabs/watermill-amqp#9. This issue can be closed.

@m110 m110 changed the title construct watermill-amqp subscriptions using a single AMQP connection [watermill-amqp] construct subscriptions using a single AMQP connection Jan 21, 2023
@m110 m110 closed this as completed Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module: subscriber
Projects
None yet
Development

No branches or pull requests

6 participants