Skip to content

Commit 48fdef4

Browse files
author
J. T. L
committed
0.0.5: add amqp_expires setting, fix #5
1 parent 9192773 commit 48fdef4

3 files changed

Lines changed: 23 additions & 14 deletions

File tree

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ Usage
2828
interested in severe weather alerts (which can be found at
2929
[http://dd.weather.gc.ca/alerts/cap/][2]), then the subtopic
3030
`"alerts.cap.#"` is appropriate.
31-
* `amqp_queue` (defaults to `"q_anonymous_node-eccc_$RANDOM"`): the name
32-
of the queue to subscribe to. In general, this should simply be a
33-
unique string starting with `q_anonymous`; the default (which selects a
34-
random name) should be adequate for the common case. However, you
35-
should override the default to something nonrandom if you enable
36-
`amqp_durable`, below.
31+
* `amqp_queue` (defaults to `"node-eccc_$RANDOM"`): the name of the queue
32+
to subscribe to. In general, this should simply be a unique string; the
33+
default (which selects a random name) should be adequate for the common
34+
case. However, you should override the default to something nonrandom
35+
if you enable `amqp_durable`, below.
36+
* `amqp_expires` (defaults to `3*3600*1000`): how long (in milliseconds)
37+
the queue will survive after all clients have disconnected. (This is
38+
only meaningful if `amqp_durable`, below, is set.)
3739
* `amqp_durable` (defaults to `false`): notifies the AMQP server as to
3840
whether the queue should be durable (e.g. persist in case all clients
3941
disconnect). This is advisable in production settings where it is
4042
imperative that messages should not get lost; however, it should be
41-
used with care, since a prolonged outage may cause a queue to become
42-
extremely full and induce server problems at ECCC. (And, possibly, get
43-
our client banned. So be nice!)
43+
used with care (alongside `amqp_expires`, see above), since it is
44+
impolite to leave discarded queues lying around the ECCC server.
4445

4546
This function returns an EventEmitter that emits the following events:
4647

@@ -52,7 +53,7 @@ Usage
5253

5354
The AMQP connection is robust, automatically reconnecting to the server on
5455
failure (though if the queue is not durable, messages sent in the meantime
55-
will be lost).
56+
may be lost).
5657

5758
[1]: http://dd.weather.gc.ca/
5859
[2]: http://dd.weather.gc.ca/alerts/cap/

index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function listen(options) {
1919
let amqp_user = "anonymous";
2020
let amqp_password = "anonymous";
2121
let amqp_subtopic = "#";
22-
let amqp_queue = "q_anonymous_" + APPLICATION + "_" + random_string();
22+
let amqp_queue = APPLICATION + "_" + random_string();
23+
let amqp_expires = 10800000; // three hours in milliseconds
2324
let amqp_durable = false;
2425
if(options) {
2526
if(options.amqp_user) {
@@ -34,6 +35,9 @@ function listen(options) {
3435
if(options.amqp_queue) {
3536
amqp_queue = options.amqp_queue;
3637
}
38+
if(options.amqp_expires > 0) {
39+
amqp_expires = options.amqp_expires;
40+
}
3741
if(options.amqp_durable) {
3842
amqp_durable = options.amqp_durable;
3943
}
@@ -63,8 +67,12 @@ function listen(options) {
6367
// failure), create a queue and bind it to the requested exchange and topic.
6468
connection.on("ready", () => {
6569
connection.queue(
66-
amqp_queue,
67-
{durable: amqp_durable, autoDelete: !amqp_durable},
70+
"q_" + amqp_user + "_" + amqp_queue,
71+
{
72+
durable: amqp_durable,
73+
autoDelete: !amqp_durable,
74+
arguments: {"x-expires": amqp_expires},
75+
},
6876
q => {
6977
q.bind(AMQP_EXCHANGE, AMQP_TOPIC_PREFIX + "." + amqp_subtopic);
7078

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-eccc",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "consume data from Environment and Climate Change Canada",
55
"license": "CC0",
66
"dependencies": {

0 commit comments

Comments
 (0)