<div class="gmail_quote"><div>Hi Ricardo,</div><div><br></div><div>There are several problems in your code, both on the sender and on the receiver side.</div><div><br></div><div>[sender]</div><div><br></div><div>If you use the library node-amqp provided here <a href="https://github.com/postwait/node-amqp">https://github.com/postwait/node-amqp</a>,</div>
<div>you may install it with npm (the node package manager), using the following command in a shell:</div><div>$ npm install -g amqp</div><div>This will install the amqp library in the directory /lib/node_modules of your node installation directory.</div>
<div>Now, check that you have properly added /lib/node_modules to your NODE_PATH.</div><div>If it is the case, your import is require('amqp') and not require('./amqp')</div><div><br></div><div>So here is the code you should use:</div>
<div><br></div><div><div>var amqp = require('amqp');</div><div><br></div><div>var connection = amqp.createConnection({ host: 'localhost' });</div><div><br></div><div>// Wait for connection to become established.</div>
<div>connection.on('ready', function () {</div><div> var x = connection.exchange()</div><div> var q = connection.queue("aqueuename",</div><div> { autoDelete: true, durable: false, exclusive: false });</div>
<div> // Wait for the queue to be declared.<span class="Apple-tab-span" style="white-space:pre">        </span></div><div> q.on('queueDeclareOk', function(){</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>x.publish('aqueuename', "bar");</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>connection.end();</div><div> });</div><div>});</div></div><div><br></div><div><br></div><div>[receiver]</div><div><br></div><div>I hadn't ever use AsyncoreConnection, but you can use BlockingConnection :</div>
<div><br></div><div><br></div><div><div>#!/usr/bin/env python</div><div>import pika</div><div><br></div><div>connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))</div><div>channel = connection.channel()</div>
<div><br></div><div>q = channel.queue_declare(queue='aqueuename',</div><div> auto_delete=True,</div><div> durable=False,</div><div> exclusive=False)</div>
<div><br></div><div>print ' [*] Waiting for messages. To exit press CTRL+C'</div><div><br></div><div>def callback(ch, method, properties, body):</div><div> print " [x] Received %r" % (body,)</div><div>
<br></div><div>channel.basic_consume(callback,</div><div> queue='aqueuename',</div><div> no_ack=True)</div><div><br></div><div>channel.start_consuming()</div></div><div><br>
</div><div><br></div><div>Cheers,</div><div>Gabriel</div><div><br></div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">On 20/10/11 16:55, </span>Ricardo<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); "> Brizido wrote:</span></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">For some reason I can't get this example to work:<br>
<br>
<br>
[sender]<br>
var sys = require('sys');<br>
var amqp = require('./amqp');<br>
<br>
var connection = amqp.createConnection({ host: 'localhost' });<br>
<br>
// Wait for connection to become established.<br>
connection.addListener('ready', function () {<br>
var x = connection.exchange()<br>
var q = connection.queue("aqueuename",<br>
{ autoDelete: true, durable: false, exclusive: false });<br>
x.publish('aqueuename', {foo: "bar"});<br>
});<br>
<br>
[receiver]<br>
#!/usr/bin/env python<br>
import pika<br>
<br>
connection = pika.AsyncoreConnection(pika.ConnectionParameters(<br>
host='localhost'))<br>
channel = connection.channel()<br>
<br>
q = channel.queue_declare(queue='aqueuename',<br>
auto_delete=True,<br>
durable=False,<br>
exclusive=False)<br>
<br>
print ' [*] Waiting for messages. To exit press CTRL+C'<br>
<br>
def callback(ch, method, properties, body):<br>
print " [x] Received %r" % (body,)<br>
<br>
channel.basic_consume(callback,<br>
queue='aqueuename',<br>
no_ack=True)<br>
<br>
pika.asyncore_loop()<br>
<br>
<br>
I wanted to used a BlockingConnection. Do you know if this works with<br>
a BlockingConnection?<br>
<br>
<br>
Thanks<br>
<br>
Ricardo<br></blockquote></div>