Note that there are some explanatory texts on larger screens.

plurals
  1. POObject transfer between Node.js and Django using AMQP
    primarykey
    data
    text
    <p>I'm beginning with websockets and I'm very confused with the number libraries and configuration options. I just want to setup a project where a node.js server calls a method in python/django and when the last has finished, it transfers the result back to the node.js server. This is what I have so far: </p> <p>Nodes.js AMQP from <a href="http://www.rabbitmq.com/blog/2011/08/16/using-the-rabbitmq-service-on-cloud-foundry-with-nodejs/" rel="nofollow">this tutorial</a>:</p> <pre><code>var conn = amqp.createConnection(); conn.on('ready', function(){ var exchange = conn.exchange('?1', {'type': 'fanout', durable: false}, function() { exchange.publish('?2', {add: [1,2]}); }); }); </code></pre> <p>Django Celery from <a href="http://ask.github.com/django-celery/getting-started/first-steps-with-django.html" rel="nofollow">this tutorial</a>:</p> <pre><code>from celery.decorators import task @task() def add(x, y): return x + y </code></pre> <p>I don't know if this is the way to go, and I would be glad if someone could shed a light on this issue.</p> <p>--- <strong>EDIT</strong></p> <p>I succeed in making a simple string transfer using AMQP:</p> <h2>test.py</h2> <pre><code> import pika connection = pika.BlockingConnection(pika.ConnectionParameters( host='localhost')) channel = connection.channel() channel.queue_declare(queue='task_queue', durable=True) print ' [*] Waiting for messages. To exit press CTRL+C' def callback(ch, method, props, body): print " [x] Received %r" % (body,) response = body + " MODIFIED" #response = get_a_concept() print " [x] Done" ch.basic_publish(exchange='', routing_key=props.reply_to, properties=pika.BasicProperties(correlation_id = \ props.correlation_id), body=str(response)) ch.basic_ack(delivery_tag = method.delivery_tag) channel.basic_qos(prefetch_count=1) channel.basic_consume(callback, queue='task_queue') channel.start_consuming() </code></pre> <h2>app.js</h2> <pre><code> var connection = amqp.createConnection({ host: 'localhost' }); connection.addListener('ready', function() { var exchange = connection.exchange('', { 'type' : 'direct', durable : false }, function() { var queue = connection.queue('incoming', { durable : false, exclusive : true }, function() { queue.subscribe(function(msg) { console.log("received message: "); console.log(msg.data.toString()); }); }); exchange.publish('task_queue', "it works!", { 'replyTo' : 'incoming' }); }); </code></pre> <p>});</p> <hr> <p>Still, I'm not sure if this is the best implementation, I'm not even using queue.bind() method here. The problem arises when I try to pass a complex object (json or even a simple array). Changing this line </p> <pre><code> body= (["a","b","c"])#str(response)) </code></pre> <p>causes the following error:</p> <pre><code> Traceback (most recent call last): File "test.py", line 56, in &lt;module&gt; channel.start_consuming() File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 293, in start_consuming (...) File "/Library/Python/2.7/site-packages/pika/simplebuffer.py", line 62, in write self.buf.write(data) TypeError: must be string or read-only character buffer, not list </code></pre> <p>Is there any solution for serializing complex objects? Am I missing something?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload