primer cambio
This commit is contained in:
28
node_modules/amqplib/examples/tutorials/callback_api/emit_log.js
generated
vendored
Normal file
28
node_modules/amqplib/examples/tutorials/callback_api/emit_log.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const exchange = 'logs';
|
||||
const text = process.argv.slice(2).join(' ') || 'info: Hello World!';
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertExchange(exchange, 'fanout', { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.publish(exchange, '', Buffer.from(text));
|
||||
console.log(" [x] Sent '%s'", text);
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
30
node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js
generated
vendored
Normal file
30
node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const exchange = 'direct_logs';
|
||||
const args = process.argv.slice(2);
|
||||
const routingKey = (args.length > 0) ? args[0] : 'info';
|
||||
const text = args.slice(1).join(' ') || 'Hello World!';
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertExchange(exchange, 'direct', { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.publish(exchange, routingKey, Buffer.from(text));
|
||||
console.log(" [x] Sent '%s'", text);
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
30
node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js
generated
vendored
Normal file
30
node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const exchange = 'topic_logs';
|
||||
const args = process.argv.slice(2);
|
||||
const routingKey = (args.length > 0) ? args[0] : 'info';
|
||||
const text = args.slice(1).join(' ') || 'Hello World!';
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertExchange(exchange, 'topic', { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.publish(exchange, routingKey, Buffer.from(text));
|
||||
console.log(" [x] Sent '%s'", text);
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
28
node_modules/amqplib/examples/tutorials/callback_api/new_task.js
generated
vendored
Normal file
28
node_modules/amqplib/examples/tutorials/callback_api/new_task.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const queue = 'task_queue';
|
||||
const text = process.argv.slice(2).join(' ') || "Hello World!";
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertQueue(queue, { durable: true }, (err) => {
|
||||
if (err) return bails(err, connection);
|
||||
channel.sendToQueue(queue, Buffer.from(text), { persistent: true });
|
||||
console.log(" [x] Sent '%s'", text);
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
36
node_modules/amqplib/examples/tutorials/callback_api/receive.js
generated
vendored
Normal file
36
node_modules/amqplib/examples/tutorials/callback_api/receive.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const queue = 'hello';
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
|
||||
process.once('SIGINT', () => {
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
|
||||
channel.assertQueue(queue, { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.consume(queue, (message) => {
|
||||
if (message) console.log(" [x] Received '%s'", message.content.toString());
|
||||
else console.warn(' [x] Consumer cancelled');
|
||||
}, { noAck: true }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
console.log(" [*] Waiting for logs. To exit press CTRL+C.");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
42
node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js
generated
vendored
Normal file
42
node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const exchange = 'logs';
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
|
||||
process.once('SIGINT', () => {
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
|
||||
channel.assertExchange(exchange, 'fanout', { durable: false }, (err, { queue }) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.bindQueue(queue, exchange, '', {}, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.consume(queue, (message) => {
|
||||
if (message) console.log(" [x] '%s'", message.content.toString());
|
||||
else console.warn(' [x] Consumer cancelled');
|
||||
}, { noAck: true }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
console.log(" [*] Waiting for logs. To exit press CTRL+C.");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
57
node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js
generated
vendored
Normal file
57
node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
const { basename } = require('path');
|
||||
|
||||
const exchange = 'direct_logs';
|
||||
const severities = process.argv.slice(2);
|
||||
if (severities.length < 1) {
|
||||
console.log('Usage %s [info] [warning] [error]', basename(process.argv[1]));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
|
||||
process.once('SIGINT', () => {
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
|
||||
channel.assertExchange(exchange, 'direct', { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.consume(queue, (message) => {
|
||||
if (message) console.log(" [x] %s:'%s'", message.fields.routingKey, message.content.toString());
|
||||
else console.warn(' [x] Consumer cancelled');
|
||||
}, {noAck: true}, function(err) {
|
||||
if (err) return bail(err, connection);
|
||||
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
|
||||
subscribeAll(channel, queue, severities, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function subscribeAll(channel, queue, bindingKeys, cb) {
|
||||
if (bindingKeys.length === 0) return cb();
|
||||
const bindingKey = bindingKeys.shift();
|
||||
channel.bindQueue(queue, exchange, bindingKey, {}, (err) => {
|
||||
if (err) return cb(err);
|
||||
subscribeAll(channel, queue, bindingKeys, cb);
|
||||
});
|
||||
}
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
58
node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js
generated
vendored
Normal file
58
node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
const { basename } = require('path');
|
||||
|
||||
const exchange = 'topic_logs';
|
||||
const severities = process.argv.slice(2);
|
||||
if (severities.length < 1) {
|
||||
console.log('Usage %s [info] [warning] [error]', basename(process.argv[1]));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
|
||||
process.once('SIGINT', () => {
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
|
||||
channel.assertExchange(exchange, 'topic', { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.consume(queue, (message) => {
|
||||
if (message) console.log(" [x] %s:'%s'", message.fields.routingKey, message.content.toString());
|
||||
else console.warn(' [x] Consumer cancelled');
|
||||
}, {noAck: true}, function(err) {
|
||||
if (err) return bail(err, connection);
|
||||
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
|
||||
subscribeAll(channel, queue, severities, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function subscribeAll(channel, queue, bindingKeys, cb) {
|
||||
if (bindingKeys.length === 0) return cb();
|
||||
const bindingKey = bindingKeys.shift();
|
||||
channel.bindQueue(queue, exchange, bindingKey, {}, (err) => {
|
||||
if (err) return cb(err);
|
||||
subscribeAll(channel, queue, bindingKeys, cb);
|
||||
});
|
||||
}
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
51
node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js
generated
vendored
Normal file
51
node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
const { basename } = require('path');
|
||||
const { v4: uuid } = require('uuid');
|
||||
|
||||
const queue = 'rpc_queue';
|
||||
|
||||
const n = parseInt(process.argv[2], 10);
|
||||
if (isNaN(n)) {
|
||||
console.warn('Usage: %s number', basename(process.argv[1]));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertQueue('', { exclusive: true }, (err, { queue: replyTo }) => {
|
||||
if (err) return bail(err, connection);
|
||||
|
||||
const correlationId = uuid();
|
||||
channel.consume(replyTo, (message) => {
|
||||
if (!message) console.warn(' [x] Consumer cancelled');
|
||||
else if (message.properties.correlationId === correlationId) {
|
||||
console.log(' [.] Got %d', message.content.toString());
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
})
|
||||
}
|
||||
}, { noAck: true });
|
||||
|
||||
channel.assertQueue(queue, { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
console.log(' [x] Requesting fib(%d)', n);
|
||||
channel.sendToQueue(queue, Buffer.from(n.toString()), {
|
||||
correlationId,
|
||||
replyTo
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
55
node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js
generated
vendored
Normal file
55
node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const queue = 'rpc_queue';
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
|
||||
process.once('SIGINT', () => {
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
|
||||
channel.assertQueue(queue, { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.prefetch(1);
|
||||
channel.consume(queue, (message) => {
|
||||
const n = parseInt(message.content.toString(), 10);
|
||||
console.log(' [.] fib(%d)', n);
|
||||
const response = fib(n);
|
||||
channel.sendToQueue(message.properties.replyTo, Buffer.from(response.toString()), {
|
||||
correlationId: message.properties.correlationId
|
||||
});
|
||||
channel.ack(message);
|
||||
}, { noAck: false }, function(err) {
|
||||
if (err) return bail(err, conn);
|
||||
console.log(' [x] Awaiting RPC requests. To exit press CTRL+C.');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function fib(n) {
|
||||
// Do it the ridiculous, but not most ridiculous, way. For better,
|
||||
// see http://nayuki.eigenstate.org/page/fast-fibonacci-algorithms
|
||||
let a = 0, b = 1;
|
||||
for (let i=0; i < n; i++) {
|
||||
let c = a + b;
|
||||
a = b; b = c;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
28
node_modules/amqplib/examples/tutorials/callback_api/send.js
generated
vendored
Normal file
28
node_modules/amqplib/examples/tutorials/callback_api/send.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const queue = 'hello';
|
||||
const text = 'Hello World!';
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.assertQueue(queue, { durable: false }, (err) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.sendToQueue(queue, Buffer.from(text));
|
||||
console.log(" [x] Sent '%s'", text);
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
39
node_modules/amqplib/examples/tutorials/callback_api/worker.js
generated
vendored
Normal file
39
node_modules/amqplib/examples/tutorials/callback_api/worker.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const amqp = require('amqplib/callback_api');
|
||||
|
||||
const queue = 'task_queue';
|
||||
|
||||
amqp.connect((err, connection) => {
|
||||
if (err) return bail(err);
|
||||
connection.createChannel((err, channel) => {
|
||||
if (err) return bail(err, connection);
|
||||
|
||||
process.once('SIGINT', () => {
|
||||
channel.close(() => {
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
|
||||
channel.assertQueue(queue, { durable: true }, (err, { queue }) => {
|
||||
if (err) return bail(err, connection);
|
||||
channel.consume(queue, (message) => {
|
||||
const text = message.content.toString();
|
||||
console.log(" [x] Received '%s'", text);
|
||||
const seconds = text.split('.').length - 1;
|
||||
setTimeout(() => {
|
||||
console.log(" [x] Done");
|
||||
channel.ack(message);
|
||||
}, seconds * 1000);
|
||||
}, { noAck: false });
|
||||
console.log(" [*] Waiting for messages. To exit press CTRL+C");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function bail(err, connection) {
|
||||
console.error(err);
|
||||
if (connection) connection.close(() => {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user