1 | winston = require 'winston'
|
2 | amqp = require 'amqplib'
|
3 | amqpUrl = "amqp://guest:guest@localhost:5672"
|
4 | q = require 'q'
|
5 |
|
6 | uniqueId = -> id = ""; id += Math.random().toString(36).substr(2) while id.length < 32; id.substr 0, 32
|
7 |
|
8 | logger = (level = 'debug') ->
|
9 | new winston.Logger
|
10 | transports: [ new winston.transports.Console level: level, colorize: true, timestamp: true ]
|
11 |
|
12 | deleteExchange = (connection, exchangeName) ->
|
13 | q(connection.createChannel()).then (channel) ->
|
14 | channel.deleteExchange(exchangeName)
|
15 |
|
16 | connect = ->
|
17 | q(amqp.connect(amqpUrl))
|
18 |
|
19 | deliver = (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 |
|
26 | exports.logger = logger
|
27 | exports.deleteExchange = deleteExchange
|
28 | exports.connect = connect
|
29 | exports.deliver = deliver
|
30 | exports.amqpUrl = amqpUrl
|
31 | exports.uniqueId = uniqueId |
\ | No newline at end of file |