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

Handle RabbitMQ reconnect and message resending #12

Merged
merged 17 commits into from
Oct 2, 2020

Conversation

aolivier
Copy link

Replaces the underlying amqplib library with node-amqp-connection-manager, which provides support for network reconnects and handles re-sending of any messages sent while the network is down.

Note that node-amqp-connection-manager currently has a reported bug and does not currently handle drain events. While it guarantees receipt of all published messages, it does not resend failed messages when a drain emit is fired. This would ideally be fixed in the library and allow us to resend on drain like we did previously (instead of on a fixed time interval). See jwalton/node-amqp-connection-manager#129

Closes #11

alexovaltech and others added 7 commits September 23, 2020 13:10
-Library manages connection retries and is basically a drop-in
replacement for amqplib
-Provides a setup function which can be used to specifiy desired
behavior on connection reconnect (queue assertion, etc.)
- All direct references to a Channel become references to a persistent
ChannelWrapper
- Added ability to pass onConnect function in IAmqpCacoonConfig
- onConnect is called each time a channel connection re-connects and can
be used to assert queues and perform other setup tasks
- Cleaning up a bit how we add a setup function to the ChannelWrapper
-After replacing amqpLib with AmqpConnectionManager
- Assuming node-amqp-connection-library guarantees receipt of a
published message, we shouldn't have to manually resend on drain
- HOWEVER, it seems there is a bug in this library and it doesn't handle
drain events. Creating a separate story for that!
-Removed it in code previously but not in test
Have more things to write, but updating references to amqp to refer to amqp-node-connection-manager
alexovaltech and others added 2 commits September 27, 2020 11:32
- Added test that can be run manually to ensure that published messages
sent while network is down are received when network reconnects
- Added simple callbacks to AmqpCacoon config so we can attach events to
onConnect / onDisconnect events emitted by AmqpChannelManager
readme.md Outdated
- Publish flow control included out of the box (Wait for drain event if we can't publish)
- timeout if drain event does not occurs after some amount of time when channel is not ready to receive a publish
- Simple interace around `node-amqp-manager`
- ~Publish flow control included out of the box (Wait for drain event if we can't publish)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick typo fix: In GitHub, a you'll need double-tildes to strikethrough: ~~text to strikethrough~~.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link

@jasonalderman-valtech jasonalderman-valtech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just the minor typo in the README.

Copy link
Contributor

@daniellmorris daniellmorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically this appears really solid. I have some small comments in the code but nothing major.

During one of these comments ensure you using semantic-release syntax to ensure the version number gets incremented for the release process. See https://github.com/semantic-release/semantic-release for full details on the semantic-release commit message stuff. Essentially, one of your commit messages needs to have something like perf(feature_name): something about the features and then semantic-release will automatically increment a major version number when creating the npm release package.

package.json Outdated
@@ -16,6 +16,8 @@
"test": "mocha -r ts-node/register ./tests/**/*.test.ts"
},
"dependencies": {
"@types/amqp-connection-manager": "^2.0.10",
"amqp-connection-manager": "^3.2.1",
"amqplib": "^0.5.5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove amqplib

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I'm seeing rules-js as a dependancy. I'm sure that was my fault at some point but could you remove that while you are at it too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daniellmorris I pulled out rules-js, but couldn't pull out amqplib completely because we still need access to some of the classes in there (and they're not exposed by amqp-connection-manager). We can discuss if ya want.

readme.md Show resolved Hide resolved
src/index.ts Outdated

if (config.port) {
fullHostNameString = fullHostNameString + ':' + config.port;
private pubChannelWrapper: ChannelWrapper | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like your tabwidth is set to 4 spaces instead of 2. Lets fix that for consistency :).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe, uh oh...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/index.ts Outdated
// Connect if needed
this.connection =
this.connection ||
(await amqp.connect([this.fullHostName], this.amqp_opts));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, it appears that amqp.connect doesn't return a promise. We should be able to remove the await here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think I'm wrong then feel free to ignore this comment because it doesn't actually hurt the code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're correct!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

src/index.ts Outdated
logger?: Logger;
};
onChannelConnect?: ConnectCallback;
onBrokerConnect?: Function;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there are reason we are using Function instead of something like the following?

onBrokerConnect?: () => void
// Or if you really need it to be any input and any output
onBrokerConnect?: (...args: any[]) => any

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh just probably my own JS / TS clumsiness!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Alex Olivier and others added 8 commits September 29, 2020 09:23
@aolivier aolivier merged commit 0041840 into master Oct 2, 2020
@aolivier aolivier deleted the alex/IPB-139-network-retries branch October 2, 2020 21:46
@daniellmorris
Copy link
Contributor

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reconnection after an RMQ drop/disconnect
4 participants