typespeed 2.0.13 → 2.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.decorator.js +0 -1
- package/dist/database.decorator.js +0 -1
- package/dist/default/express-server.class.js +0 -1
- package/dist/default/log-default.class.js +0 -1
- package/dist/default/node-cache.class.js +0 -1
- package/dist/default/rabbitmq.class.js +0 -1
- package/dist/default/read-write-db.class.js +0 -1
- package/dist/default/redis.class.js +0 -1
- package/dist/factory/cache-factory.class.js +0 -1
- package/dist/factory/data-source-factory.class.js +0 -1
- package/dist/factory/log-factory.class.js +0 -1
- package/dist/factory/server-factory.class.js +0 -1
- package/dist/route.decorator.js +0 -1
- package/dist/scaffold/command.js +0 -1
- package/dist/typespeed.d.ts +133 -12
- package/dist/typespeed.js +1 -1
- package/package.json +2 -2
- package/src/typespeed.d.ts +133 -0
- package/src/typespeed.ts +2 -1
- package/test/node_modules/.package-lock.json +112 -4
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +17 -0
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +30 -0
- package/test/node_modules/@acuminous/bitsyntax/LICENSE +6 -0
- package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +21 -0
- package/test/node_modules/@acuminous/bitsyntax/Makefile +15 -0
- package/test/node_modules/@acuminous/bitsyntax/README.md +308 -0
- package/test/node_modules/@acuminous/bitsyntax/index.js +10 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +303 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +142 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +67 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +232 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +32 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +1173 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +119 -0
- package/test/node_modules/@acuminous/bitsyntax/package.json +36 -0
- package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +50 -0
- package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +193 -0
- package/test/node_modules/@types/node/README.md +1 -1
- package/test/node_modules/@types/node/buffer.d.ts +5 -2
- package/test/node_modules/@types/node/child_process.d.ts +27 -0
- package/test/node_modules/@types/node/globals.d.ts +1 -0
- package/test/node_modules/@types/node/package.json +2 -2
- package/test/node_modules/@types/node/test.d.ts +43 -20
- package/test/node_modules/@types/node/ts4.8/buffer.d.ts +5 -2
- package/test/node_modules/@types/node/ts4.8/child_process.d.ts +27 -0
- package/test/node_modules/@types/node/ts4.8/globals.d.ts +1 -0
- package/test/node_modules/@types/node/ts4.8/test.d.ts +43 -19
- package/test/node_modules/@types/node/ts4.8/url.d.ts +3 -3
- package/test/node_modules/@types/node/ts4.8/util.d.ts +1 -1
- package/test/node_modules/@types/node/url.d.ts +3 -3
- package/test/node_modules/@types/node/util.d.ts +1 -1
- package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/test/node_modules/amqplib/.github/workflows/test.yml +38 -0
- package/test/node_modules/amqplib/CHANGELOG.md +430 -0
- package/test/node_modules/amqplib/LICENSE +6 -0
- package/test/node_modules/amqplib/LICENSE-MIT +21 -0
- package/test/node_modules/amqplib/Makefile +47 -0
- package/test/node_modules/amqplib/README.md +157 -0
- package/test/node_modules/amqplib/bin/generate-defs.js +722 -0
- package/test/node_modules/amqplib/callback_api.js +22 -0
- package/test/node_modules/amqplib/channel_api.js +16 -0
- package/test/node_modules/amqplib/examples/headers.js +42 -0
- package/test/node_modules/amqplib/examples/receive_generator.js +39 -0
- package/test/node_modules/amqplib/examples/send_generators.js +42 -0
- package/test/node_modules/amqplib/examples/ssl.js +64 -0
- package/test/node_modules/amqplib/examples/tutorials/README.md +93 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +28 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +30 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +27 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +27 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +30 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +36 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +56 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +55 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +49 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +45 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +29 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +35 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log.js +19 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +20 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +19 -0
- package/test/node_modules/amqplib/examples/tutorials/new_task.js +18 -0
- package/test/node_modules/amqplib/examples/tutorials/package.json +16 -0
- package/test/node_modules/amqplib/examples/tutorials/receive.js +21 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +28 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +44 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +43 -0
- package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +52 -0
- package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +39 -0
- package/test/node_modules/amqplib/examples/tutorials/send.js +23 -0
- package/test/node_modules/amqplib/examples/tutorials/worker.js +28 -0
- package/test/node_modules/amqplib/examples/waitForConfirms.js +22 -0
- package/test/node_modules/amqplib/lib/api_args.js +314 -0
- package/test/node_modules/amqplib/lib/bitset.js +130 -0
- package/test/node_modules/amqplib/lib/callback_model.js +327 -0
- package/test/node_modules/amqplib/lib/channel.js +499 -0
- package/test/node_modules/amqplib/lib/channel_model.js +302 -0
- package/test/node_modules/amqplib/lib/codec.js +321 -0
- package/test/node_modules/amqplib/lib/connect.js +189 -0
- package/test/node_modules/amqplib/lib/connection.js +663 -0
- package/test/node_modules/amqplib/lib/credentials.js +42 -0
- package/test/node_modules/amqplib/lib/defs.js +4966 -0
- package/test/node_modules/amqplib/lib/error.js +24 -0
- package/test/node_modules/amqplib/lib/format.js +40 -0
- package/test/node_modules/amqplib/lib/frame.js +113 -0
- package/test/node_modules/amqplib/lib/heartbeat.js +89 -0
- package/test/node_modules/amqplib/lib/mux.js +129 -0
- package/test/node_modules/amqplib/package.json +37 -0
- package/test/node_modules/amqplib/test/bitset.js +69 -0
- package/test/node_modules/amqplib/test/callback_api.js +312 -0
- package/test/node_modules/amqplib/test/channel.js +621 -0
- package/test/node_modules/amqplib/test/channel_api.js +596 -0
- package/test/node_modules/amqplib/test/codec.js +237 -0
- package/test/node_modules/amqplib/test/connect.js +197 -0
- package/test/node_modules/amqplib/test/connection.js +390 -0
- package/test/node_modules/amqplib/test/data.js +254 -0
- package/test/node_modules/amqplib/test/frame.js +198 -0
- package/test/node_modules/amqplib/test/mux.js +204 -0
- package/test/node_modules/amqplib/test/util.js +219 -0
- package/test/node_modules/buffer-more-ints/.travis.yml +6 -0
- package/test/node_modules/buffer-more-ints/LICENSE +19 -0
- package/test/node_modules/buffer-more-ints/README.md +69 -0
- package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +183 -0
- package/test/node_modules/buffer-more-ints/buffer-more-ints.js +432 -0
- package/test/node_modules/buffer-more-ints/package.json +19 -0
- package/test/node_modules/buffer-more-ints/polyfill.js +71 -0
- package/test/node_modules/core-util-is/LICENSE +19 -0
- package/test/node_modules/core-util-is/README.md +3 -0
- package/test/node_modules/core-util-is/lib/util.js +107 -0
- package/test/node_modules/core-util-is/package.json +38 -0
- package/test/node_modules/debug/LICENSE +20 -0
- package/test/node_modules/debug/README.md +481 -0
- package/test/node_modules/debug/package.json +59 -0
- package/test/node_modules/debug/src/browser.js +269 -0
- package/test/node_modules/debug/src/common.js +274 -0
- package/test/node_modules/debug/src/index.js +10 -0
- package/test/node_modules/debug/src/node.js +263 -0
- package/test/node_modules/inherits/LICENSE +16 -0
- package/test/node_modules/inherits/README.md +42 -0
- package/test/node_modules/inherits/inherits.js +9 -0
- package/test/node_modules/inherits/inherits_browser.js +27 -0
- package/test/node_modules/inherits/package.json +29 -0
- package/test/node_modules/isarray/README.md +54 -0
- package/test/node_modules/isarray/build/build.js +209 -0
- package/test/node_modules/isarray/component.json +19 -0
- package/test/node_modules/isarray/index.js +3 -0
- package/test/node_modules/isarray/package.json +25 -0
- package/test/node_modules/ms/index.js +162 -0
- package/test/node_modules/ms/license.md +21 -0
- package/test/node_modules/ms/package.json +37 -0
- package/test/node_modules/ms/readme.md +60 -0
- package/test/node_modules/querystringify/LICENSE +22 -0
- package/test/node_modules/querystringify/README.md +61 -0
- package/test/node_modules/querystringify/index.js +118 -0
- package/test/node_modules/querystringify/package.json +38 -0
- package/test/node_modules/readable-stream/LICENSE +18 -0
- package/test/node_modules/readable-stream/README.md +15 -0
- package/test/node_modules/readable-stream/duplex.js +1 -0
- package/test/node_modules/readable-stream/float.patch +923 -0
- package/test/node_modules/readable-stream/lib/_stream_duplex.js +89 -0
- package/test/node_modules/readable-stream/lib/_stream_passthrough.js +46 -0
- package/test/node_modules/readable-stream/lib/_stream_readable.js +951 -0
- package/test/node_modules/readable-stream/lib/_stream_transform.js +209 -0
- package/test/node_modules/readable-stream/lib/_stream_writable.js +477 -0
- package/test/node_modules/readable-stream/package.json +32 -0
- package/test/node_modules/readable-stream/passthrough.js +1 -0
- package/test/node_modules/readable-stream/readable.js +10 -0
- package/test/node_modules/readable-stream/transform.js +1 -0
- package/test/node_modules/readable-stream/writable.js +1 -0
- package/test/node_modules/requires-port/.travis.yml +19 -0
- package/test/node_modules/requires-port/LICENSE +22 -0
- package/test/node_modules/requires-port/README.md +47 -0
- package/test/node_modules/requires-port/index.js +38 -0
- package/test/node_modules/requires-port/package.json +47 -0
- package/test/node_modules/requires-port/test.js +98 -0
- package/test/node_modules/safe-buffer/LICENSE +21 -0
- package/test/node_modules/safe-buffer/README.md +584 -0
- package/test/node_modules/safe-buffer/index.d.ts +187 -0
- package/test/node_modules/safe-buffer/index.js +62 -0
- package/test/node_modules/safe-buffer/package.json +37 -0
- package/test/node_modules/string_decoder/LICENSE +20 -0
- package/test/node_modules/string_decoder/README.md +7 -0
- package/test/node_modules/string_decoder/index.js +221 -0
- package/test/node_modules/string_decoder/package.json +25 -0
- package/test/node_modules/url-parse/LICENSE +22 -0
- package/test/node_modules/url-parse/README.md +153 -0
- package/test/node_modules/url-parse/dist/url-parse.js +755 -0
- package/test/node_modules/url-parse/dist/url-parse.min.js +1 -0
- package/test/node_modules/url-parse/dist/url-parse.min.js.map +1 -0
- package/test/node_modules/url-parse/index.js +589 -0
- package/test/node_modules/url-parse/package.json +49 -0
- package/test/src/test-mq.class.ts +1 -2
- package/tsconfig.json +4 -3
- package/dist/core.decorator.d.ts +0 -18
- package/dist/core.decorator.js.map +0 -1
- package/dist/database.decorator.d.ts +0 -24
- package/dist/database.decorator.js.map +0 -1
- package/dist/default/express-server.class.d.ts +0 -15
- package/dist/default/express-server.class.js.map +0 -1
- package/dist/default/log-default.class.d.ts +0 -6
- package/dist/default/log-default.class.js.map +0 -1
- package/dist/default/node-cache.class.d.ts +0 -13
- package/dist/default/node-cache.class.js.map +0 -1
- package/dist/default/rabbitmq.class.d.ts +0 -9
- package/dist/default/rabbitmq.class.js.map +0 -1
- package/dist/default/read-write-db.class.d.ts +0 -10
- package/dist/default/read-write-db.class.js.map +0 -1
- package/dist/default/redis.class.d.ts +0 -5
- package/dist/default/redis.class.js.map +0 -1
- package/dist/factory/cache-factory.class.d.ts +0 -7
- package/dist/factory/cache-factory.class.js.map +0 -1
- package/dist/factory/data-source-factory.class.d.ts +0 -4
- package/dist/factory/data-source-factory.class.js.map +0 -1
- package/dist/factory/log-factory.class.d.ts +0 -4
- package/dist/factory/log-factory.class.js.map +0 -1
- package/dist/factory/server-factory.class.d.ts +0 -6
- package/dist/factory/server-factory.class.js.map +0 -1
- package/dist/route.decorator.d.ts +0 -8
- package/dist/route.decorator.js.map +0 -1
- package/dist/scaffold/command.d.ts +0 -2
- package/dist/scaffold/command.js.map +0 -1
- package/dist/typespeed.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib/callback_api');
|
|
4
|
+
|
|
5
|
+
function fib(n) {
|
|
6
|
+
var a = 0, b = 1;
|
|
7
|
+
for (var i=0; i < n; i++) {
|
|
8
|
+
var c = a + b;
|
|
9
|
+
a = b; b = c;
|
|
10
|
+
}
|
|
11
|
+
return a;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function bail(err, conn) {
|
|
15
|
+
console.error(err);
|
|
16
|
+
if (conn) conn.close(function() { process.exit(1); });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function on_connect(err, conn) {
|
|
20
|
+
if (err !== null) return bail(err);
|
|
21
|
+
|
|
22
|
+
process.once('SIGINT', function() { conn.close(); });
|
|
23
|
+
|
|
24
|
+
var q = 'rpc_queue';
|
|
25
|
+
|
|
26
|
+
conn.createChannel(function(err, ch) {
|
|
27
|
+
ch.assertQueue(q, {durable: false});
|
|
28
|
+
ch.prefetch(1);
|
|
29
|
+
ch.consume(q, reply, {noAck:false}, function(err) {
|
|
30
|
+
if (err !== null) return bail(err, conn);
|
|
31
|
+
console.log(' [x] Awaiting RPC requests');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
function reply(msg) {
|
|
35
|
+
var n = parseInt(msg.content.toString());
|
|
36
|
+
console.log(' [.] fib(%d)', n);
|
|
37
|
+
ch.sendToQueue(msg.properties.replyTo,
|
|
38
|
+
Buffer.from(fib(n).toString()),
|
|
39
|
+
{correlationId: msg.properties.correlationId});
|
|
40
|
+
ch.ack(msg);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
amqp.connect(on_connect);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib/callback_api');
|
|
4
|
+
|
|
5
|
+
function bail(err, conn) {
|
|
6
|
+
console.error(err);
|
|
7
|
+
if (conn) conn.close(function() { process.exit(1); });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function on_connect(err, conn) {
|
|
11
|
+
if (err !== null) return bail(err);
|
|
12
|
+
|
|
13
|
+
var q = 'hello';
|
|
14
|
+
var msg = 'Hello World!';
|
|
15
|
+
|
|
16
|
+
function on_channel_open(err, ch) {
|
|
17
|
+
if (err !== null) return bail(err, conn);
|
|
18
|
+
ch.assertQueue(q, {durable: false}, function(err, ok) {
|
|
19
|
+
if (err !== null) return bail(err, conn);
|
|
20
|
+
ch.sendToQueue(q, Buffer.from(msg));
|
|
21
|
+
console.log(" [x] Sent '%s'", msg);
|
|
22
|
+
ch.close(function() { conn.close(); });
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
conn.createChannel(on_channel_open);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
amqp.connect(on_connect);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib/callback_api');
|
|
4
|
+
|
|
5
|
+
function bail(err, conn) {
|
|
6
|
+
console.error(err);
|
|
7
|
+
if (conn) conn.close(function() { process.exit(1); });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function on_connect(err, conn) {
|
|
11
|
+
if (err !== null) return bail(err);
|
|
12
|
+
process.once('SIGINT', function() { conn.close(); });
|
|
13
|
+
|
|
14
|
+
var q = 'task_queue';
|
|
15
|
+
|
|
16
|
+
conn.createChannel(function(err, ch) {
|
|
17
|
+
if (err !== null) return bail(err, conn);
|
|
18
|
+
ch.assertQueue(q, {durable: true}, function(err, _ok) {
|
|
19
|
+
ch.consume(q, doWork, {noAck: false});
|
|
20
|
+
console.log(" [*] Waiting for messages. To exit press CTRL+C");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function doWork(msg) {
|
|
24
|
+
var body = msg.content.toString();
|
|
25
|
+
console.log(" [x] Received '%s'", body);
|
|
26
|
+
var secs = body.split('.').length - 1;
|
|
27
|
+
setTimeout(function() {
|
|
28
|
+
console.log(" [x] Done");
|
|
29
|
+
ch.ack(msg);
|
|
30
|
+
}, secs * 1000);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
amqp.connect(on_connect);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
|
|
5
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
6
|
+
return conn.createChannel().then(function(ch) {
|
|
7
|
+
var ex = 'logs';
|
|
8
|
+
var ok = ch.assertExchange(ex, 'fanout', {durable: false})
|
|
9
|
+
|
|
10
|
+
var message = process.argv.slice(2).join(' ') ||
|
|
11
|
+
'info: Hello World!';
|
|
12
|
+
|
|
13
|
+
return ok.then(function() {
|
|
14
|
+
ch.publish(ex, '', Buffer.from(message));
|
|
15
|
+
console.log(" [x] Sent '%s'", message);
|
|
16
|
+
return ch.close();
|
|
17
|
+
});
|
|
18
|
+
}).finally(function() { conn.close(); });
|
|
19
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
|
|
5
|
+
var args = process.argv.slice(2);
|
|
6
|
+
var severity = (args.length > 0) ? args[0] : 'info';
|
|
7
|
+
var message = args.slice(1).join(' ') || 'Hello World!';
|
|
8
|
+
|
|
9
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
10
|
+
return conn.createChannel().then(function(ch) {
|
|
11
|
+
var ex = 'direct_logs';
|
|
12
|
+
var ok = ch.assertExchange(ex, 'direct', {durable: false});
|
|
13
|
+
|
|
14
|
+
return ok.then(function() {
|
|
15
|
+
ch.publish(ex, severity, Buffer.from(message));
|
|
16
|
+
console.log(" [x] Sent %s:'%s'", severity, message);
|
|
17
|
+
return ch.close();
|
|
18
|
+
});
|
|
19
|
+
}).finally(function() { conn.close(); });
|
|
20
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
|
|
5
|
+
var args = process.argv.slice(2);
|
|
6
|
+
var key = (args.length > 0) ? args[0] : 'info';
|
|
7
|
+
var message = args.slice(1).join(' ') || 'Hello World!';
|
|
8
|
+
|
|
9
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
10
|
+
return conn.createChannel().then(function(ch) {
|
|
11
|
+
var ex = 'topic_logs';
|
|
12
|
+
var ok = ch.assertExchange(ex, 'topic', {durable: false});
|
|
13
|
+
return ok.then(function() {
|
|
14
|
+
ch.publish(ex, key, Buffer.from(message));
|
|
15
|
+
console.log(" [x] Sent %s:'%s'", key, message);
|
|
16
|
+
return ch.close();
|
|
17
|
+
});
|
|
18
|
+
}).finally(function() { conn.close(); })
|
|
19
|
+
}).catch(console.log);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Post a new task to the work queue
|
|
3
|
+
|
|
4
|
+
var amqp = require('amqplib');
|
|
5
|
+
|
|
6
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
7
|
+
return conn.createChannel().then(function(ch) {
|
|
8
|
+
var q = 'task_queue';
|
|
9
|
+
var ok = ch.assertQueue(q, {durable: true});
|
|
10
|
+
|
|
11
|
+
return ok.then(function() {
|
|
12
|
+
var msg = process.argv.slice(2).join(' ') || "Hello World!";
|
|
13
|
+
ch.sendToQueue(q, Buffer.from(msg), {deliveryMode: true});
|
|
14
|
+
console.log(" [x] Sent '%s'", msg);
|
|
15
|
+
return ch.close();
|
|
16
|
+
});
|
|
17
|
+
}).finally(function() { conn.close(); });
|
|
18
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "amqplib-tutorials",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The RabbitMQ tutorials, ported to amqplib",
|
|
5
|
+
"main": "send.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"amqplib": "../..",
|
|
8
|
+
"uuid": "*"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"repository": "",
|
|
14
|
+
"author": "Michael Bridgen <mikeb@squaremobius.net>",
|
|
15
|
+
"license": "MPL 2.0"
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
|
|
5
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
6
|
+
process.once('SIGINT', function() { conn.close(); });
|
|
7
|
+
return conn.createChannel().then(function(ch) {
|
|
8
|
+
|
|
9
|
+
var ok = ch.assertQueue('hello', {durable: false});
|
|
10
|
+
|
|
11
|
+
ok = ok.then(function(_qok) {
|
|
12
|
+
return ch.consume('hello', function(msg) {
|
|
13
|
+
console.log(" [x] Received '%s'", msg.content.toString());
|
|
14
|
+
}, {noAck: true});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return ok.then(function(_consumeOk) {
|
|
18
|
+
console.log(' [*] Waiting for messages. To exit press CTRL+C');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
|
|
5
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
6
|
+
process.once('SIGINT', function() { conn.close(); });
|
|
7
|
+
return conn.createChannel().then(function(ch) {
|
|
8
|
+
var ok = ch.assertExchange('logs', 'fanout', {durable: false});
|
|
9
|
+
ok = ok.then(function() {
|
|
10
|
+
return ch.assertQueue('', {exclusive: true});
|
|
11
|
+
});
|
|
12
|
+
ok = ok.then(function(qok) {
|
|
13
|
+
return ch.bindQueue(qok.queue, 'logs', '').then(function() {
|
|
14
|
+
return qok.queue;
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
ok = ok.then(function(queue) {
|
|
18
|
+
return ch.consume(queue, logMessage, {noAck: true});
|
|
19
|
+
});
|
|
20
|
+
return ok.then(function() {
|
|
21
|
+
console.log(' [*] Waiting for logs. To exit press CTRL+C');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function logMessage(msg) {
|
|
25
|
+
console.log(" [x] '%s'", msg.content.toString());
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
var basename = require('path').basename;
|
|
5
|
+
|
|
6
|
+
var severities = process.argv.slice(2);
|
|
7
|
+
if (severities.length < 1) {
|
|
8
|
+
console.warn('Usage: %s [info] [warning] [error]',
|
|
9
|
+
basename(process.argv[1]));
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
14
|
+
process.once('SIGINT', function() { conn.close(); });
|
|
15
|
+
return conn.createChannel().then(function(ch) {
|
|
16
|
+
var ex = 'direct_logs';
|
|
17
|
+
|
|
18
|
+
var ok = ch.assertExchange(ex, 'direct', {durable: false});
|
|
19
|
+
|
|
20
|
+
ok = ok.then(function() {
|
|
21
|
+
return ch.assertQueue('', {exclusive: true});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
ok = ok.then(function(qok) {
|
|
25
|
+
var queue = qok.queue;
|
|
26
|
+
return Promise.all(severities.map(function(sev) {
|
|
27
|
+
ch.bindQueue(queue, ex, sev);
|
|
28
|
+
})).then(function() { return queue; });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
ok = ok.then(function(queue) {
|
|
32
|
+
return ch.consume(queue, logMessage, {noAck: true});
|
|
33
|
+
});
|
|
34
|
+
return ok.then(function() {
|
|
35
|
+
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function logMessage(msg) {
|
|
39
|
+
console.log(" [x] %s:'%s'",
|
|
40
|
+
msg.fields.routingKey,
|
|
41
|
+
msg.content.toString());
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
var basename = require('path').basename;
|
|
5
|
+
|
|
6
|
+
var keys = process.argv.slice(2);
|
|
7
|
+
if (keys.length < 1) {
|
|
8
|
+
console.log('Usage: %s pattern [pattern...]',
|
|
9
|
+
basename(process.argv[1]));
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
14
|
+
process.once('SIGINT', function() { conn.close(); });
|
|
15
|
+
return conn.createChannel().then(function(ch) {
|
|
16
|
+
var ex = 'topic_logs';
|
|
17
|
+
var ok = ch.assertExchange(ex, 'topic', {durable: false});
|
|
18
|
+
|
|
19
|
+
ok = ok.then(function() {
|
|
20
|
+
return ch.assertQueue('', {exclusive: true});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
ok = ok.then(function(qok) {
|
|
24
|
+
var queue = qok.queue;
|
|
25
|
+
return Promise.all(keys.map(function(rk) {
|
|
26
|
+
ch.bindQueue(queue, ex, rk);
|
|
27
|
+
})).then(function() { return queue; });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
ok = ok.then(function(queue) {
|
|
31
|
+
return ch.consume(queue, logMessage, {noAck: true});
|
|
32
|
+
});
|
|
33
|
+
return ok.then(function() {
|
|
34
|
+
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function logMessage(msg) {
|
|
38
|
+
console.log(" [x] %s:'%s'",
|
|
39
|
+
msg.fields.routingKey,
|
|
40
|
+
msg.content.toString());
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
var basename = require('path').basename;
|
|
5
|
+
var uuid = require('node-uuid');
|
|
6
|
+
|
|
7
|
+
// I've departed from the form of the original RPC tutorial, which
|
|
8
|
+
// needlessly introduces a class definition, and doesn't even
|
|
9
|
+
// parameterise the request.
|
|
10
|
+
|
|
11
|
+
var n;
|
|
12
|
+
try {
|
|
13
|
+
if (process.argv.length < 3) throw Error('Too few args');
|
|
14
|
+
n = parseInt(process.argv[2]);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.error(e);
|
|
18
|
+
console.warn('Usage: %s number', basename(process.argv[1]));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
23
|
+
return conn.createChannel().then(function(ch) {
|
|
24
|
+
return new Promise(function(resolve) {
|
|
25
|
+
var corrId = uuid();
|
|
26
|
+
function maybeAnswer(msg) {
|
|
27
|
+
if (msg.properties.correlationId === corrId) {
|
|
28
|
+
resolve(msg.content.toString());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var ok = ch.assertQueue('', {exclusive: true})
|
|
33
|
+
.then(function(qok) { return qok.queue; });
|
|
34
|
+
|
|
35
|
+
ok = ok.then(function(queue) {
|
|
36
|
+
return ch.consume(queue, maybeAnswer, {noAck: true})
|
|
37
|
+
.then(function() { return queue; });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
ok = ok.then(function(queue) {
|
|
41
|
+
console.log(' [x] Requesting fib(%d)', n);
|
|
42
|
+
ch.sendToQueue('rpc_queue', Buffer.from(n.toString()), {
|
|
43
|
+
correlationId: corrId, replyTo: queue
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
})
|
|
48
|
+
.then(function(fibN) {
|
|
49
|
+
console.log(' [.] Got %d', fibN);
|
|
50
|
+
})
|
|
51
|
+
.finally(function() { conn.close(); });
|
|
52
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
|
|
5
|
+
function fib(n) {
|
|
6
|
+
// Do it the ridiculous, but not most ridiculous, way. For better,
|
|
7
|
+
// see http://nayuki.eigenstate.org/page/fast-fibonacci-algorithms
|
|
8
|
+
var a = 0, b = 1;
|
|
9
|
+
for (var i=0; i < n; i++) {
|
|
10
|
+
var c = a + b;
|
|
11
|
+
a = b; b = c;
|
|
12
|
+
}
|
|
13
|
+
return a;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
17
|
+
process.once('SIGINT', function() { conn.close(); });
|
|
18
|
+
return conn.createChannel().then(function(ch) {
|
|
19
|
+
var q = 'rpc_queue';
|
|
20
|
+
var ok = ch.assertQueue(q, {durable: false});
|
|
21
|
+
var ok = ok.then(function() {
|
|
22
|
+
ch.prefetch(1);
|
|
23
|
+
return ch.consume(q, reply);
|
|
24
|
+
});
|
|
25
|
+
return ok.then(function() {
|
|
26
|
+
console.log(' [x] Awaiting RPC requests');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
function reply(msg) {
|
|
30
|
+
var n = parseInt(msg.content.toString());
|
|
31
|
+
console.log(' [.] fib(%d)', n);
|
|
32
|
+
var response = fib(n);
|
|
33
|
+
ch.sendToQueue(msg.properties.replyTo,
|
|
34
|
+
Buffer.from(response.toString()),
|
|
35
|
+
{correlationId: msg.properties.correlationId});
|
|
36
|
+
ch.ack(msg);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var amqp = require('amqplib');
|
|
4
|
+
|
|
5
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
6
|
+
return conn.createChannel().then(function(ch) {
|
|
7
|
+
var q = 'hello';
|
|
8
|
+
var msg = 'Hello World!';
|
|
9
|
+
|
|
10
|
+
var ok = ch.assertQueue(q, {durable: false});
|
|
11
|
+
|
|
12
|
+
return ok.then(function(_qok) {
|
|
13
|
+
// NB: `sentToQueue` and `publish` both return a boolean
|
|
14
|
+
// indicating whether it's OK to send again straight away, or
|
|
15
|
+
// (when `false`) that you should wait for the event `'drain'`
|
|
16
|
+
// to fire before writing again. We're just doing the one write,
|
|
17
|
+
// so we'll ignore it.
|
|
18
|
+
ch.sendToQueue(q, Buffer.from(msg));
|
|
19
|
+
console.log(" [x] Sent '%s'", msg);
|
|
20
|
+
return ch.close();
|
|
21
|
+
});
|
|
22
|
+
}).finally(function() { conn.close(); });
|
|
23
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Process tasks from the work queue
|
|
3
|
+
|
|
4
|
+
var amqp = require('amqplib');
|
|
5
|
+
|
|
6
|
+
amqp.connect('amqp://localhost').then(function(conn) {
|
|
7
|
+
process.once('SIGINT', function() { conn.close(); });
|
|
8
|
+
return conn.createChannel().then(function(ch) {
|
|
9
|
+
var ok = ch.assertQueue('task_queue', {durable: true});
|
|
10
|
+
ok = ok.then(function() { ch.prefetch(1); });
|
|
11
|
+
ok = ok.then(function() {
|
|
12
|
+
ch.consume('task_queue', doWork, {noAck: false});
|
|
13
|
+
console.log(" [*] Waiting for messages. To exit press CTRL+C");
|
|
14
|
+
});
|
|
15
|
+
return ok;
|
|
16
|
+
|
|
17
|
+
function doWork(msg) {
|
|
18
|
+
var body = msg.content.toString();
|
|
19
|
+
console.log(" [x] Received '%s'", body);
|
|
20
|
+
var secs = body.split('.').length - 1;
|
|
21
|
+
//console.log(" [x] Task takes %d seconds", secs);
|
|
22
|
+
setTimeout(function() {
|
|
23
|
+
console.log(" [x] Done");
|
|
24
|
+
ch.ack(msg);
|
|
25
|
+
}, secs * 1000);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}).catch(console.warn);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var amqp = require('../');
|
|
2
|
+
|
|
3
|
+
var NUM_MSGS = 20;
|
|
4
|
+
|
|
5
|
+
function mkCallback(i) {
|
|
6
|
+
return (i % 2) === 0 ? function(err) {
|
|
7
|
+
if (err !== null) { console.error('Message %d failed!', i); }
|
|
8
|
+
else { console.log('Message %d confirmed', i); }
|
|
9
|
+
} : null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
amqp.connect().then(function(c) {
|
|
13
|
+
c.createConfirmChannel().then(function(ch) {
|
|
14
|
+
for (var i=0; i < NUM_MSGS; i++) {
|
|
15
|
+
ch.publish('amq.topic', 'whatever', Buffer.from('blah'), {}, mkCallback(i));
|
|
16
|
+
}
|
|
17
|
+
ch.waitForConfirms().then(function() {
|
|
18
|
+
console.log('All messages done');
|
|
19
|
+
c.close();
|
|
20
|
+
}).catch(console.error);
|
|
21
|
+
});
|
|
22
|
+
});
|