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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/amqp defaults cleanup #650

Merged
merged 1 commit into from Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/transporters/amqp.js
Expand Up @@ -74,11 +74,15 @@ class AmqpTransporter extends Transporter {
if (typeof opts.consumeOptions !== "object")
opts.consumeOptions = {};

// The default behavior is to delete the queues after they haven't had any
// connected consumers for 2 minutes.
const autoDeleteQueuesAfterDefault = 2*60*1000;

opts.autoDeleteQueues =
opts.autoDeleteQueues === true ? 2*60*1000 :
opts.autoDeleteQueues === true ? autoDeleteQueuesAfterDefault :
typeof opts.autoDeleteQueues === "number" ? opts.autoDeleteQueues :
opts.autoDeleteQueues === false ? -1 :
-1; // Eventually we could change default
autoDeleteQueuesAfterDefault;

// Support for multiple URLs (clusters)
opts.url = Array.isArray(opts.url)
Expand Down
12 changes: 6 additions & 6 deletions test/unit/transporters/amqp.spec.js
Expand Up @@ -61,7 +61,7 @@ describe("Test AmqpTransporter constructor", () => {
messageOptions: {},
queueOptions: {},
consumeOptions: {},
autoDeleteQueues: -1
autoDeleteQueues: 120000
});
expect(transporter.connected).toBe(false);
expect(transporter.hasBuiltInBalancer).toBe(true);
Expand All @@ -80,7 +80,7 @@ describe("Test AmqpTransporter constructor", () => {
messageOptions: { expiration: 120000, persistent: true, mandatory: true },
queueOptions: { deadLetterExchange: "dlx", maxLength: 100 },
consumeOptions: { priority: 5 },
autoDeleteQueues: -1
autoDeleteQueues: 31337
};
let transporter = new AmqpTransporter(opts);
expect(transporter.opts).toEqual(opts);
Expand Down Expand Up @@ -253,7 +253,7 @@ describe("Test AmqpTransporter subscribe", () => {
expect(transporter.channel.assertQueue).toHaveBeenCalledTimes(1);
expect(transporter.channel.consume).toHaveBeenCalledTimes(1);
expect(transporter.channel.assertQueue)
.toHaveBeenCalledWith("MOL-TEST.RES.node", {});
.toHaveBeenCalledWith("MOL-TEST.RES.node", { expires: 120000 });
expect(transporter.channel.consume)
.toHaveBeenCalledWith("MOL-TEST.RES.node", jasmine.any(Function), { noAck: true });

Expand Down Expand Up @@ -292,7 +292,7 @@ describe("Test AmqpTransporter subscribe", () => {
expect(transporter.channel.assertQueue).toHaveBeenCalledTimes(1);
expect(transporter.channel.consume).toHaveBeenCalledTimes(1);
expect(transporter.channel.assertQueue)
.toHaveBeenCalledWith("MOL-TEST.REQ.node", {});
.toHaveBeenCalledWith("MOL-TEST.REQ.node", { expires: 120000 });
expect(transporter.channel.consume)
.toHaveBeenCalledWith("MOL-TEST.REQ.node", jasmine.any(Function), { noAck: false });

Expand All @@ -313,7 +313,7 @@ describe("Test AmqpTransporter subscribe", () => {
expect(transporter.channel.consume).toHaveBeenCalledTimes(1);

expect(transporter.channel.assertQueue)
.toHaveBeenCalledWith("MOL-TEST.EVENT.node", { messageTtl: 3000 }); // use ttl option
.toHaveBeenCalledWith("MOL-TEST.EVENT.node", { expires: 120000, messageTtl: 3000 }); // use ttl option
expect(transporter.channel.consume)
.toHaveBeenCalledWith("MOL-TEST.EVENT.node", jasmine.any(Function), { noAck: true });

Expand Down Expand Up @@ -410,7 +410,7 @@ describe("Test AmqpTransporter subscribe", () => {
expect(transporter.channel.consume).toHaveBeenCalledTimes(1);
expect(transporter.channel.assertQueue)
.toHaveBeenCalledWith("MOL-TEST.EVENTB.posts.cache.clear",
{ messageTtl: 3000 });
{ expires: 120000, messageTtl: 3000 });
expect(transporter.channel.consume)
.toHaveBeenCalledWith("MOL-TEST.EVENTB.posts.cache.clear", jasmine.any(Function), {});

Expand Down
2 changes: 1 addition & 1 deletion test/unit/transporters/index.spec.js
Expand Up @@ -108,7 +108,7 @@ describe("Test Transporter resolver", () => {
messageOptions: {},
queueOptions: {},
consumeOptions: {},
autoDeleteQueues: -1
autoDeleteQueues: 120000
});
});
});
Expand Down