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

Posted by Dion Almaer at 6:28 am
2 Comments

++---
2.9 rating from 19 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.