amqp.connect('amqp://localhost:5672', function (err, conn) { conn.createChannel(function (err, ch) { const q = 'hello'; ch.assertQueue(q, { durable: false }); ch.prefetch(1); console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q); ch.consume(q, function (msg) { console.log(" [x] Received %s", msg.content.toString()); }, { noAck: true }); }); });
castMessage( message : ampq.Message ) : RatingMessage { return JSON.parse( message.content.toString() ) as RatingMessage; }
amqp.connect('amqp://localhost', function(err, conn) { conn.createChannel(function(err, ch) { var q = 'myqueue'; ch.assertQueue(q, {durable: false}); console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q); ch.consume(q, function(msg) { console.log(" [x] Received %s", msg.content.toString()); }, {noAck: true}); }); });
function consumer () { amqp.connect('amqp://admin:admin@localhost:5672', function(err, conn) { if (err) { console.error("[AMQP] Error Create a connection", err.message); return setTimeout(function() {process.exit(0) }, 500); } conn.createChannel(function(err, ch) { if (err) { console.error("[AMQP] Error Create a Channel", err.message); return setTimeout(function() {process.exit(0) }, 500); } var queue = 'hello'; ch.assertQueue(queue, {durable: false}); console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", queue); ch.consume(queue, function(msg) { console.log(" [x] Received %s", msg.content.toString()); }, {noAck: true}); }); }); }
amqp.connect('amqp://localhost', function(err, conn) { conn.createChannel(function(err, ch) { var ex = 'topic_logs'; ch.assertExchange(ex, 'topic', {durable: false}); ch.assertQueue('', {exclusive: true}, function(err, q) { console.log(' [*] Waiting for logs. To exit press CTRL+C'); args.forEach(function(key) { ch.bindQueue(q.queue, ex, key); }); ch.consume(q.queue, function(msg) { console.log(" [x] %s:'%s'", msg.fields.routingKey, msg.content.toString()); }, {noAck: true}); }); }); });
connectTopicChannel() { amqp.connect(conn, (err, conn) => { if (err) { wl(err, false); } else { conn.createChannel((err, ch) => { ch.assertExchange(exchange, 'topic', { durable: true }); ch.assertQueue(queue, { exclusive: false }, (err, q) => { wl(' [*] Waiting for data. To exit press CTRL+C', true); ch.bindQueue(q.queue, exchange, rabbitMQconfig.keyPattern); // receive data and do whatever ch.consume(q.queue, (msg) => { // write message to consol using our writeLog function wl(`${msg.fields.routingKey}: ${msg.content.toString()}`, true); }, { noAck: true }); }); }); } }); }
amqp.connect('amqp://localhost:5672', function (err, conn) { conn.createChannel(function (err, ch) { ch.assertQueue(queue, { durable: false }); ch.prefetch(1); console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", queue); ch.consume(queue, async function (msg) { const { name, email } = JSON.parse(msg.content); await User.create({ name, email }); console.log(" [x] Received %s", msg.content.toString()); }, { noAck: true }); }); });
// AMQP IP amqp.connect('amqp://10.55.71.212', function(err, conn) { conn.createChannel(function(err, ch) { var q = 'hello'; ch.assertQueue(q, {durable: false}); console.log(`Waiting for messages in ${q}. To exit press CTRL+C`); ch.consume(q, function (msg) { var json = JSON.parse(msg.content.toString()); console.log("Received: ",json.msg); console.log("Value:",json.value); ch.ack(msg); }) }); });
amqp.connect('amqp://localhost', (error, connection) => { if (error) throw error; connection.createChannel((error, channel) => { if (error) throw error; const queue = "Hello"; channel.assertQueue(queue, { durable: false }); channel.consume(queue, (msg) => { console.log(" [x] Received %s", msg.content.toString()); }, { noAck: false }); }) });
amqp.connect('amqp://localhost', (error, connection) => { if (error) throw error; connection.createChannel(function (error, channel) { if (error) throw error; channel.prefetch(1); channel.assertQueue(queue, { durable: true }); channel.consume(queue, (msg) => { console.log(msg.content.toString()); setTimeout(function() { console.log(" [x] Done"); channel.ack(msg); }, 5000); }, { noAck: false }); }); });
amqp.connect('amqp://localhost', (error, connection) => { if (error) throw error; connection.createChannel(function (error, channel) { if (error) throw error; channel.assertQueue(queue, { durable: true }); channel.prefetch(1); channel.consume(queue, (msg) => { console.log(msg.content.toString()); setTimeout(function() { console.log(" [x] Done"); channel.ack(msg); }, 5000); }, { noAck: false }); }); });
amqp.connect('amqp://localhost', function(err, conn) { conn.createChannel(function(err, ch) { var q = 'hello'; ch.assertQueue(q, {durable: false}); console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q); ch.consume(q, function(msg) { console.log(" [x] Received %s", msg.content.toString()); }, {noAck: true}); }); });
amqp.connect(url, (err, conn) => { if (err) { throw err } conn.createChannel((err, channel) => { const queueName = 'queueUser' channel.assertQueue(queueName, { durable: true }) console.log('wait message....') channel.consume(queueName, message => { console.log('message: ', message.content.toString()) }, { noAck: true }) }) })
amqp.connect('amqp://localhost', function (error, connection) { if (error) throw error; connection.createChannel(function (error, channel) { if (error) throw error; const queue = 'Hello'; channel.assertQueue(queue, { durable: false }); channel.consume(queue, function(msg) { console.log(" [x] Received %s", msg.content.toString()); }, { noAck: false }); }); });
amqp.connect('amqp://admin:admin@localhost', function (error0, connection) { if (error0) { throw error0; } connection.createChannel(function (error1, channel) { if (error1) { throw error1; } var queue = 'hello'; channel.assertQueue(queue, { durable: false }); console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", queue); channel.consume(queue, function (msg) { console.log(" [x] Received %s", msg.content.toString()); }, { noAck: true }); }); });