node-amqp

node-amqp + rabbitMQ how to convert post request into message

試著忘記壹切 提交于 2019-12-12 03:53:57
问题 I have express server setup to listen post request and put the post request in message queue var express = require('express'); var app = express(); app.use(express.bodyParser()); app.post('/test-page', function(req, res) { var amqp = require('amqp'); var connection = amqp.createConnection({url: "amqp://guest:guest@localhost:5672"},{defaultExchangeName: ''}); connection.on('ready',function(){ console.log('connected'); var messageToSend = req.body; var queueToSendTo = "xyz"; connection.queue

Sending RabbitMQ messages via websockets

最后都变了- 提交于 2019-12-09 06:03:02
问题 Looking for some code samples to solve this problem :- Would like to write some code (Python or Javascript) that would act as a subscriber to a RabbitMQ queue so that on receiving a message it would broadcast the message via websockets to any connected client. I've looked at Autobahn and node.js (using "amqp" and "ws" ) but cannot get things to work as needed. Here's the server code in javascript using node.js:- var amqp = require('amqp'); var WebSocketServer = require('ws').Server var

RxJS Observable with asynchronous subscriber function

若如初见. 提交于 2019-12-06 06:54:24
问题 I'm trying to do something that feels like it should be straightforward, but is proving surprisingly difficult. I have a function to subscribe to a RabbitMQ queue. Concretely, this is the Channel.consume function here: http://www.squaremobius.net/amqp.node/channel_api.html#channel_consume It returns a promise which is resolved with a subscription id - which is needed to unsubscribe later - and also has a callback argument to invoke when messages are pulled off the queue. When I want to

RxJS Observable with asynchronous subscriber function

旧巷老猫 提交于 2019-12-04 13:15:50
I'm trying to do something that feels like it should be straightforward, but is proving surprisingly difficult. I have a function to subscribe to a RabbitMQ queue. Concretely, this is the Channel.consume function here: http://www.squaremobius.net/amqp.node/channel_api.html#channel_consume It returns a promise which is resolved with a subscription id - which is needed to unsubscribe later - and also has a callback argument to invoke when messages are pulled off the queue. When I want to unsubscribe from the queue, I'd need to cancel the consumer using the Channel.cancel function here: http:/

Should I close the channel/connection after every publish?

泪湿孤枕 提交于 2019-12-03 12:42:49
问题 I am using amqplib in Node.js, and I am not clear about the best practices in my code. Basically, my current code calls the amqp.connect() when the Node server starts up, and then uses a different channel for each producer and each consumer, never actually closing any of them. I'd like to know if that makes any sense, or should I create the channel, publish and close it every time I want to publish a message. And what about the connection? Is that a "good practice" to connect once, and then

How to requeue messages in RabbitMQ

半城伤御伤魂 提交于 2019-11-30 10:26:36
问题 After the consumer gets a message, consumer/worker does some validations and then call web service. In this phase, if any error occurs or validation fails, we want the message put back to the queue it was originally consumed from. I have read RabbitMQ documentation. But I am confused about differences between reject, nack and cancel methods. 回答1: Short answer: To requeue specific message you can pick both basic.reject or basic.nack with multiple flag set to false. basic.consume calling may

How to requeue messages in RabbitMQ

孤者浪人 提交于 2019-11-29 20:41:39
After the consumer gets a message, consumer/worker does some validations and then call web service. In this phase, if any error occurs or validation fails, we want the message put back to the queue it was originally consumed from. I have read RabbitMQ documentation. But I am confused about differences between reject, nack and cancel methods. pinepain Short answer: To requeue specific message you can pick both basic.reject or basic.nack with multiple flag set to false. basic.consume calling may also results to messages redelivering if you are using message acknowledge and there are un

RabbitMQ / AMQP: single queue, multiple consumers for same message?

本小妞迷上赌 提交于 2019-11-26 23:22:44
I am just starting to use RabbitMQ and AMQP in general. I have a queue of messages I have multiple consumers, which I would like to do different things with the same message . Most of the RabbitMQ documentation seems to be focused on round-robin, ie where a single message is consumed by a single consumer, with the load being spread between each consumer. This is indeed the behavior I witness. An example: the producer has a single queue, and send messages every 2 sec: var amqp = require('amqp'); var connection = amqp.createConnection({ host: "localhost", port: 5672 }); var count = 1; connection

RabbitMQ / AMQP: single queue, multiple consumers for same message?

那年仲夏 提交于 2019-11-26 06:12:41
问题 I am just starting to use RabbitMQ and AMQP in general. I have a queue of messages I have multiple consumers, which I would like to do different things with the same message . Most of the RabbitMQ documentation seems to be focused on round-robin, ie where a single message is consumed by a single consumer, with the load being spread between each consumer. This is indeed the behavior I witness. An example: the producer has a single queue, and send messages every 2 sec: var amqp = require(\'amqp