Saturday, January 16, 2010

Drizzle to Infinispan replication and a small code walkthrough

This post aims to explain how to build your own key/value-store applier in RabbitReplication by walking through the new Infinispan support as an example.

Infinispan is a "distributed, highly available data grid platform" and it exposes a REST interface where it is possible to manipulate the data in infinispan. For example it is a simple HTTP PUT method to store new data and a HTTP DELETE does exactly what you expect. The data is stored under resources, for RabbitReplication the data is stored under /<schema.table>/<key>. This means you can view the data in infinispan using a browser.

When I implemented the Infinispan support, I simply dropped the .war file in the webapps directory of a jetty installation and started it. Since Infinispan has a REST interface, the client library can be any HTTP client, I picked the Jersey REST client since it is incredibly easy to use.

Customizing RabbitReplication
RabbitReplication uses Guice internally for dependency injection, so, to use another KeyValue store you need to create your own Module for configuration. I'll show an example below.

To add support for a new key/value store, you need to implement an interface, org.drizzle.replication.transformer.objectstores.KeyValueStoreClient (here). It is a quite straight-forward add/get/remove interface. Look at the infinispan implementation (here) for an example. Note the @Inject on the constructor, it tells guice that the WebResource parameter should be injected when it constructs the object. You will need to put the rabbitreplication.jar file on your classpath when building your stuff.

Guice is configured in modules where you bind() an interface to an implementation, so, to configure guice to use a new KeyValueStore, we need to bind() the KeyValueStoreClient interface to the new implementation. Look at the infinispan module (here) for an example how to do it, the method annotated with @Provides is called by guice when it needs to create a KeyValueStoreClient.

To tell RabbitReplication to use your new module, you simply edit your configuration file, and set where the new Module is located, see this example. If you need to configure your new client, simply add the properties in the config file, guice will bind every property in the file to @Named(...) strings, check the Infinispan module provider method for an example how to use it.

Now, build your code into a jar, drop the jar in the lib/ directory of rabbitreplication and start RabbitReplication like this; bin/ config/ - the config file should have the custom_module set to the name of your new module.

Downloading and installing
Best way to use rabbitreplication is still to branch the code from launchpad (lp:rabbitreplication) and then write ant in the base directory, this will create a .zip and a .tgz in the dist directory. You can also download the binaries here.

  • Unpack the distribution file
  • Copy a config file from .sample to .properties in the config directory and edit the file to your liking. is the sample you want to look at if you want to try out Infinispan.
  • Start rabbitreplication by executing bin/ config/
Look at the previous posts on rabbitreplication to find out how to start a master etc.


Manik Surtani said...

Hi there

Interesting stuff, could you tell me a bit more about RabbitReplication? Is it essentially a clustering layer for Drizzle?


Marcus Eriksson said...


RabbitReplication is (still) basically a classic replication solution (like mysql does for example). One master sends row-changes to a set of slaves.

Difference is that I trust RabbitMQ to deliver the messages instead of building the message delivery inside Drizzle.

Also, RabbitReplication enables replication from an RDBMS to various NoSQL stores, see earlier posts on RabbitReplication in this blog for more on that.