Monday, December 28, 2009

Drizzle replication to WebSockets

I just pushed a WebSocket applier to RabbitReplication, and yes, it is as crazy as it sounds. It works pretty much like all appliers - it consumes drizzle transactions from  RabbitMQ, converts them into objects by inspecting annotations, marshalls the object to JSON, and then stores the JSON string. In this case it stores it to a set of websockets. RabbitReplication is deployed as a war file to Jetty 7.01 which supports websockets.


I set the demo up on my server at home (in Sweden) on a DSL line, so it might be slow, but it should show the idea, all operations are instant when latency is low (if anyone wants to host it at a better place, please let me know). Of course, it requires a WebSocket capable browser and the only one I know of is Google Chrome.

It works like this:

  1. INSERT is executed from the "drizzle client" webapp - totally separate webapp that uses drizzle jdbc to insert/update/delete data.
  2. Drizzle stores the transaction in the database and in the transaction log.
  3. Master extractor extracts the transaction and publishes it to RabbitMQ
  4. Slave applier consumes the transaction from RabbitMQ
  5. Applier transforms the transaction to JSON
  6. Applier writes the JSON to a set of websockets
  7. Javascript voodoo is performed to make it visible
Possible real usecases
The demo app just shows what is possible, but a real use case could be that someone has a drizzle backed forum and want to add some real time post-updates to some front page somewhere. This would be real easy, simply start a new slave configured for WebSocket application (of course RabbitReplication is already used for other replication needs :) ), convert the JSON to something that makes sense and they are set! If someone has a cool usecase, please let me know and i'll build a more realistic demo app!

1 comment:

Peter Lubbers said...

Great demo!
I'll have to learn a bit more about Drizzle--sounds very interesting.
At Kaazing, we have created Stomp and AMQP client libraries on top of WebSocket that you can use to directly talk to a backend server like RabbitMQ (my favorite MQ) or ActiveMQ.
Peter Lubbers, Kaazing