UNPKG

1.01 kBtext/coffeescriptView Raw
1winston = require 'winston'
2amqp = require 'amqplib'
3amqpUrl = "amqp://guest:guest@localhost:5672"
4q = require 'q'
5
6uniqueId = -> id = ""; id += Math.random().toString(36).substr(2) while id.length < 32; id.substr 0, 32
7
8logger = (level = 'debug') ->
9 new winston.Logger
10 transports: [ new winston.transports.Console level: level, colorize: true, timestamp: true ]
11
12deleteExchange = (connection, exchangeName) ->
13 q(connection.createChannel()).then (channel) ->
14 channel.deleteExchange(exchangeName)
15
16connect = ->
17 q(amqp.connect(amqpUrl))
18
19deliver = (connection, queue, topicName, message) ->
20 q(connection.createChannel()).then (channel) ->
21 messageToSend = new Buffer(JSON.stringify(message))
22 channel.publish(topicName, queue, messageToSend)
23 channel.sendToQueue(queue, messageToSend)
24 channel
25
26exports.logger = logger
27exports.deleteExchange = deleteExchange
28exports.connect = connect
29exports.deliver = deliver
30exports.amqpUrl = amqpUrl
31exports.uniqueId = uniqueId
\No newline at end of file