/** * Subscribe to balanced action commands * * @param {String} action * @memberof AmqpTransporter */ subscribeBalancedRequest(action) { const queue = `${this.prefix}.${PACKET_REQUEST}B.${action}`; return this.channel.assertQueue(queue, this._getQueueOptions(PACKET_REQUEST, true)) .then(() => this.channel.consume( queue, this._consumeCB(PACKET_REQUEST, true), this.opts.consumeOptions )); }
const needAck = [PACKET_REQUEST].indexOf(cmd) !== -1; return this.channel.assertQueue(topic, this._getQueueOptions(cmd)) .then(() => this.channel.consume( topic, this.channel.assertQueue(queueName, this._getQueueOptions(cmd)), ]) .then(() => this.broker.Promise.all([
const produce = async (queue, message, durable = false, persistent = false) => { const connect = await amqp.connect(config.rabbitMqUrl) const channel = await connect.createChannel() await channel.assertQueue(queue, { durable }) await channel.sendToQueue(queue, Buffer.from(message), { persistent }) console.log('Message produced: ', queue, message) }
initialize() { return amqp .connect('amqp://localhost') .then(conn => conn.createChannel()) .then(channel => { this.channel = channel; return this.channel.assertQueue(this.qName); }) .then(q => this.queue = q.queue) .catch(err => console.log(err.stack)) ; }
amqp.connect('amqp://localhost', function(err, conn) { conn.createChannel(function(err, ch) { var q = 'myqueue'; var msg = 'hello world 1'; ch.assertQueue(q, {durable: false}); // Note: on Node 6 Buffer.from(msg) should be used ch.sendToQueue(q, Buffer.from(msg)); console.log(" [x] Sent %s", msg); }); setTimeout(function() { conn.close(); process.exit(0) }, 500); });
async function init() { const connection = await amqp.connect(config.rabbitmq.url) const e = config.rabbitmq.exchange const channel = await connection.createChannel() await channel.assertExchange(e, 'fanout', { durable: false, autoDelete: true }) const q = await channel.assertQueue('', { exclusive: true }) await channel.bindQueue(q.queue, e, '') channel.consume(q.queue, (msg) => { console.log(msg.content.toString()) channel.ack(msg) }) }
async connect () { this.connection = await amqp.connect(this.connectionString) this.channel = await this.connection.createChannel() await this.channel.assertQueue(this.queueName) return null }
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 }); }); });
async function init() { const connection = await amqp.connect(config.rabbitmq.url) const q = config.rabbitmq.channel const channel = await connection.createChannel() await channel.assertQueue(q, { autoDelete: false }) channel.sendToQueue(q, Buffer.from(process.argv[2] || 'something to do')) setTimeout(async () => { await connection.close() }, 500) }
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}); }); });
async function init() { const connection = await amqp.connect(config.rabbitmq.url) const q = config.rabbitmq.channel const channel = await connection.createChannel() await channel.assertQueue(q, { autoDelete: false }) channel.prefetch(1) channel.consume(q, (msg) => { console.log(msg.content.toString()) channel.ack(msg) }) }
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 }); }); });
amqp.connect('amqp://localhost', function(err, conn) { conn.createChannel(function(err, ch) { var q = 'hello'; var msg = 'Hello World!'; ch.assertQueue(q, {durable: false}); // Note: on Node 6 Buffer.from(msg) should be used ch.sendToQueue(q, new Buffer(msg)); console.log(" [x] Sent %s", msg); }); setTimeout(function() { conn.close(); process.exit(0) }, 500); });
/** * Subscribe to balanced event command * * @param {String} event * @param {String} group * @memberof AmqpTransporter */ subscribeBalancedEvent(event, group) { const queue = `${this.prefix}.${PACKET_EVENT}B.${group}.${event}`; return this.channel.assertQueue(queue, this._getQueueOptions(PACKET_EVENT + "LB", true)) .then(() => this.channel.consume( queue, this._consumeCB(PACKET_EVENT, true), this.opts.consumeOptions )); }
async connect () { this.connection = await amqp.connect(this.connectionString) this.channel = await this.connection.createChannel() await this.channel.assertQueue(this.queueName) return null }