Skip to content

Commit

Permalink
0.0.5: add amqp_expires setting, fix #5
Browse files Browse the repository at this point in the history
  • Loading branch information
J. T. L committed Aug 17, 2017
1 parent 9192773 commit 48fdef4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
21 changes: 11 additions & 10 deletions README.md
Expand Up @@ -28,19 +28,20 @@ Usage
interested in severe weather alerts (which can be found at
[http://dd.weather.gc.ca/alerts/cap/][2]), then the subtopic
`"alerts.cap.#"` is appropriate.
* `amqp_queue` (defaults to `"q_anonymous_node-eccc_$RANDOM"`): the name
of the queue to subscribe to. In general, this should simply be a
unique string starting with `q_anonymous`; the default (which selects a
random name) should be adequate for the common case. However, you
should override the default to something nonrandom if you enable
`amqp_durable`, below.
* `amqp_queue` (defaults to `"node-eccc_$RANDOM"`): the name of the queue
to subscribe to. In general, this should simply be a unique string; the
default (which selects a random name) should be adequate for the common
case. However, you should override the default to something nonrandom
if you enable `amqp_durable`, below.
* `amqp_expires` (defaults to `3*3600*1000`): how long (in milliseconds)
the queue will survive after all clients have disconnected. (This is
only meaningful if `amqp_durable`, below, is set.)
* `amqp_durable` (defaults to `false`): notifies the AMQP server as to
whether the queue should be durable (e.g. persist in case all clients
disconnect). This is advisable in production settings where it is
imperative that messages should not get lost; however, it should be
used with care, since a prolonged outage may cause a queue to become
extremely full and induce server problems at ECCC. (And, possibly, get
our client banned. So be nice!)
used with care (alongside `amqp_expires`, see above), since it is
impolite to leave discarded queues lying around the ECCC server.

This function returns an EventEmitter that emits the following events:

Expand All @@ -52,7 +53,7 @@ Usage

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

[1]: http://dd.weather.gc.ca/
[2]: http://dd.weather.gc.ca/alerts/cap/
14 changes: 11 additions & 3 deletions index.js
Expand Up @@ -19,7 +19,8 @@ function listen(options) {
let amqp_user = "anonymous";
let amqp_password = "anonymous";
let amqp_subtopic = "#";
let amqp_queue = "q_anonymous_" + APPLICATION + "_" + random_string();
let amqp_queue = APPLICATION + "_" + random_string();
let amqp_expires = 10800000; // three hours in milliseconds
let amqp_durable = false;
if(options) {
if(options.amqp_user) {
Expand All @@ -34,6 +35,9 @@ function listen(options) {
if(options.amqp_queue) {
amqp_queue = options.amqp_queue;
}
if(options.amqp_expires > 0) {
amqp_expires = options.amqp_expires;
}
if(options.amqp_durable) {
amqp_durable = options.amqp_durable;
}
Expand Down Expand Up @@ -63,8 +67,12 @@ function listen(options) {
// failure), create a queue and bind it to the requested exchange and topic.
connection.on("ready", () => {
connection.queue(
amqp_queue,
{durable: amqp_durable, autoDelete: !amqp_durable},
"q_" + amqp_user + "_" + amqp_queue,
{
durable: amqp_durable,
autoDelete: !amqp_durable,
arguments: {"x-expires": amqp_expires},
},
q => {
q.bind(AMQP_EXCHANGE, AMQP_TOPIC_PREFIX + "." + amqp_subtopic);

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "node-eccc",
"version": "0.0.4",
"version": "0.0.5",
"description": "consume data from Environment and Climate Change Canada",
"license": "CC0",
"dependencies": {
Expand Down

0 comments on commit 48fdef4

Please sign in to comment.