[rabbitmq-discuss] pika and node.amqp interop

gabriel adgeg gabrieladgeg at gmail.com
Fri Oct 21 14:19:02 BST 2011


Hi Ricardo,

There are several problems in your code, both on the sender and on the
receiver side.

[sender]

If you use the library node-amqp provided here
https://github.com/postwait/node-amqp,
you may install it with npm  (the node package manager), using the following
command in a shell:
$ npm install -g amqp
This will install the amqp library in the directory /lib/node_modules of
your node installation directory.
Now, check that you have properly added  /lib/node_modules to your
NODE_PATH.
If it is the case, your import is require('amqp') and not require('./amqp')

So here is the code you should use:

var amqp = require('amqp');

var connection = amqp.createConnection({ host: 'localhost' });

// Wait for connection to become established.
connection.on('ready', function () {
   var x = connection.exchange()
   var q = connection.queue("aqueuename",
            { autoDelete: true, durable: false, exclusive: false });
   // Wait for the queue to be declared.
   q.on('queueDeclareOk', function(){
x.publish('aqueuename', "bar");
connection.end();
   });
});


[receiver]

I hadn't ever use AsyncoreConnection, but you can use BlockingConnection :


#!/usr/bin/env python
import pika

connection =
pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

q = channel.queue_declare(queue='aqueuename',
                        auto_delete=True,
                        durable=False,
                        exclusive=False)

print ' [*] Waiting for messages. To exit press CTRL+C'

def callback(ch, method, properties, body):
   print " [x] Received %r" % (body,)

channel.basic_consume(callback,
                     queue='aqueuename',
                     no_ack=True)

channel.start_consuming()


Cheers,
Gabriel


On 20/10/11 16:55, Ricardo Brizido wrote:


> For some reason I can't get this example to work:
>
>
> [sender]
> var sys = require('sys');
> var amqp = require('./amqp');
>
> var connection = amqp.createConnection({ host: 'localhost' });
>
> // Wait for connection to become established.
> connection.addListener('ready', function () {
>    var x = connection.exchange()
>    var q = connection.queue("aqueuename",
>             { autoDelete: true, durable: false, exclusive: false });
>    x.publish('aqueuename', {foo: "bar"});
> });
>
> [receiver]
> #!/usr/bin/env python
> import pika
>
> connection = pika.AsyncoreConnection(pika.ConnectionParameters(
>        host='localhost'))
> channel = connection.channel()
>
> q = channel.queue_declare(queue='aqueuename',
>                         auto_delete=True,
>                         durable=False,
>                         exclusive=False)
>
> print ' [*] Waiting for messages. To exit press CTRL+C'
>
> def callback(ch, method, properties, body):
>    print " [x] Received %r" % (body,)
>
> channel.basic_consume(callback,
>                      queue='aqueuename',
>                      no_ack=True)
>
> pika.asyncore_loop()
>
>
> I wanted to used a BlockingConnection. Do you know if this works with
> a BlockingConnection?
>
>
> Thanks
>
> Ricardo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20111021/f7f5399c/attachment.htm>


More information about the rabbitmq-discuss mailing list