Created
May 6, 2013 16:03
-
-
Save shiroyuki/5526085 to your computer and use it in GitHub Desktop.
Sample for node-amqp Event-driven Architecture
This file contains hidden or 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
| // This code is just conceptual to illustrate the proposed future change. | |
| var amqp = require('amqp'), | |
| connection = amqp.createConnection({ host: 'dev.rabbitmq.com' }); | |
| connection.on('ready', function () { | |
| function onMyQueueMessageReceived(message) { | |
| console.log(message); | |
| } | |
| function onMyQueueDeclared(q, feedback) { | |
| // feedback has the name of the queue (feedback.queueName), feedback.messageCount and feedback.consumerCount | |
| // Catch all messages | |
| q.bind('#'); | |
| // Receive messages | |
| q.subscribe(); | |
| } | |
| // Add listeners | |
| connection.on('queue.my-queue.declared', onMyQueueDeclared); | |
| connection.on('queue.my-queue.message_received', onMyQueueMessageReceived); | |
| // Declare "my-queue" queue. | |
| connection.declare_queue('my-queue'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment