安裝erlang服務javascript
下載地址 http://www.erlang.org/downloadshtml
安裝RabbitMQjava
下載地址 http://www.rabbitmq.com/download.htmlnode
windows上安裝完成以後,rabbitmq將做爲系統服務自啓動。(使用rabbitmq-plugins.bat enable rabbitmq_management能夠開啓網頁管理界面)git
npm install amqp
var amqp = require('amqp');
var connection = amqp.createConnection();
// add this for better debuging
connection.on('error', function(e) {
console.log("Error from amqp: ", e);
});
// Wait for connection to become established.
connection.on('ready', function () {
// Use the default 'amq.topic' exchange
console.log("connected to----"+ connection.serverProperties.product);
connection.publish("my-queue",{hello:'world'});
});
var amqp = require('amqp');
var connection = amqp.createConnection();
// add this for better debuging
connection.on('error', function(e) {
console.log("Error from amqp: ", e);
});
// Wait for connection to become established.
connection.on('ready', function () {
// Use the default 'amq.topic' exchange
connection.queue('my-queue', function (q) {
// Catch all messages
q.bind('#');
// Receive messages
q.subscribe(function (message) {
// Print messages to stdout
console.log(message);
});
});
});
connection.exchange("my-exchange", options={type:'fanout'}, function(exchange) {
console.log("***************");
var q = connection.queue("my-queue");
q.bind(exchange,'my-queue');
exchange.publish('my-queue',{hello:'world'});
});
connection.queue('my-queue', function (q) {
// Receive messages
q.bind('my-exchange','#');
q.subscribe(function (message) {
// Print messages to stdout
console.log(message);
});
});