Answer the question
In order to leave comments, you need to log in
Do I need to pass Options to RabbitMQ every time?
Good afternoon! I use the amqp
library for the node. Since there is no sane guide for this thing, I studied PHP / Python versions. Faced with a cardinal misunderstanding of the initialization of the queue and decided to write a wrapper over it all:
# Reqyures
events = require 'events'
amqp = require 'amqp'
# Init
EventEmitter = events.EventEmitter
QUEUE_NAME = "test_q"
EXCHANGE_NAME = "test_e"
class AmqpConnection extends EventEmitter
constructor: ->
@connection = amqp.createConnection {
host: 'localhost'
port: 5672
login: 'test'
password: '123456'
vhost: '/'
}
# @queue = undefined
@connection.on 'ready', =>
@connection.exchange EXCHANGE_NAME,
type: 'topic'
autoDelete: false
durable: true
confirm: true
deliveryMode: 2
, (@exchange)=>
@connection.queue QUEUE_NAME,
type: 'topic'
autoDelete: false
durable: true
confirm: true
deliveryMode: 2
, (@queue)=>
@queue.bind @exchange, QUEUE_NAME, =>
@.emit 'ready', {
@connection
@exchange
@queue
}
@connection.on 'error', (err)=>
@.emit 'error', err
sendMessage: (message, callback)->
@exchange.publish QUEUE_NAME, message, {
mandatory: true
deliveryMode: 2
}, (err)=>
callback err, !err
subscribe: (count, callback)->
@queue.subscribe {
ack: true
prefetchCount: count
}, callback
ac = new AmqpConnection()
module.exports = ac
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question