Created
February 3, 2016 21:08
-
-
Save dvideby0/7e4bd842db3bbe2d8529 to your computer and use it in GitHub Desktop.
This is a basic example of how to use wascally and "topic" based queues. Make sure you run the receiver.js file first to setup the bindings. You must have a local version of rabbitmq installed on your machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rabbit = require('wascally'); | |
var rabbitConfig = { | |
connection: { | |
user: null, | |
pass: null, | |
server: '127.0.0.1', | |
port: 5672, | |
vhost: null | |
}, | |
exchanges: [ | |
{name: 'testing', type: 'topic', persistent: true} | |
], | |
queues: [ | |
{ | |
name: 'testqueue', | |
limit: 100, | |
queueLimit: 100000, | |
subscribe: true, | |
durable: true | |
} | |
], | |
bindings: [ | |
{ | |
exchange: 'testing', target: 'testqueue', | |
keys: [ | |
'testqueue.type1', | |
'testqueue.type2' | |
] | |
} | |
] | |
}; | |
rabbit.handle('testqueue.type1', function(message) { | |
console.log('expecting type 1: ', message.body); | |
message.ack(); | |
}); | |
rabbit.handle('testqueue.type2', function(message) { | |
console.log('expecting type 2: ', message.body); | |
message.ack(); | |
}); | |
rabbit.configure(rabbitConfig).done(function() { | |
console.log('Connection to RabbitMQ established...'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rabbit = require('wascally'); | |
var rabbitConfig = { | |
connection: { | |
user: null, | |
pass: null, | |
server: '127.0.0.1', | |
port: 5672, | |
vhost: null | |
}, | |
exchanges: [ | |
{name: 'testing', type: 'topic', persistent: true} | |
] | |
}; | |
rabbit.configure(rabbitConfig).done(function() { | |
console.log('Connection to RabbitMQ established...'); | |
setInterval(function() { | |
rabbit.publish('testing', { | |
routingKey: 'testqueue.type1', | |
type: 'testqueue.type1', | |
body: {type: 1, message: 'This is a test'} | |
}); | |
rabbit.publish('testing', { | |
routingKey: 'testqueue.type2', | |
type: 'testqueue.type2', | |
body: {type: 2, message: 'This is a test'} | |
}); | |
}, 2000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment