Skip to content

Commit

Permalink
Merge pull request #650 from oliversalzburg/feature/amqp-defaults-cle…
Browse files Browse the repository at this point in the history
…anup

Feature/amqp defaults cleanup
  • Loading branch information
icebob committed Jan 7, 2020
2 parents 09164a3 + dc61c33 commit 40968ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
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

0 comments on commit 40968ca

Please sign in to comment.