Activate your free membership today | Log-in

Tuesday, September 8th, 2009

Kamaloka: AMQP implementation in JS

Category: Comet, JavaScript

<>p>Would you like to talk messaging directly from the browser? Kamaloka is a new library that speaks AMQP. You can easily tie to Orbited but also, in theory, any other library that speaks TCPSockets.

JAVASCRIPT:
  1.  
  2.    Orbited.settings.port = 9000;
  3.    amqp_broker_port = 7000;
  4.  
  5.    amqp_conn = amqp.Connection({host: 'localhost',
  6.                                 port: amqp_broker_port,
  7.                                 send_hook: function(msg) { // for debugging
  8.                                                        append_msg('SENT', msg);
  9.                                                   },
  10.                                 recive_hook: function(data) { // for debugging
  11.                                                         append_msg('RECV', data);
  12.                                                     }
  13.                              });
  14.     amqp_conn.start();
  15.  
  16.     // You should have your server generate a UUID since browser methods
  17.     // are unreliable at best
  18.     session = amqp_conn.create_session('not_a_great_id' + (new Date().getTime() + Math.random()));
  19.  
  20.     var fedoraproject = "org.fedoraproject-" + session.name;
  21.     session.Queue('declare', {queue:fedoraproject, exclusive:true});
  22.     session.Exchange('bind', {exchange: "amq.topic",
  23.                               queue: fedoraproject,
  24.                               binding_key: "org.fedoraproject.#"});
  25.  
  26.     // Bind each queue to the control queue so we know when to stop
  27.     session.Exchange('bind', {exchange:"amq.topic",
  28.                               queue: fedoraproject,
  29.                               binding_key:"control"});
  30.  

Related Content:

Posted by Dion Almaer at 6:28 am
2 Comments

++---
2.9 rating from 14 votes

2 Comments »

Comments feed TrackBack URI

xmlsockets, wow.

Comment by Darkimmortal — September 8, 2009

Leave a comment

You must be logged in to post a comment.