Wednesday, October 19, 2011

Spring 3.x and Cassandra using Hector

To config Spring with Cassandra, you can use the HectorTemplate class in the Hector core. the configuration is something like this:

[sourcecode language="xml"]
<bean id="hectorTemplate"
class="me.prettyprint.cassandra.service.spring.HectorTemplateImpl"
init-method="init">
<property name="cluster">
<bean class="me.prettyprint.cassandra.service.ThriftCluster">
<constructor-arg value="${cassandra.clustername}" />
<constructor-arg>
<bean
class="me.prettyprint.cassandra.service.CassandraHostConfigurator">
<constructor-arg value="${cassandra.dburl}" />
</bean>
</constructor-arg>
</bean>
</property>
<property name="keyspaceName" value="${cassandra.keyspace}" />
<property name="replicationStrategyClass"
value="org.apache.cassandra.locator.SimpleStrategy" />
<property name="replicationFactor" value="${cassandra.replicationfactor}" />
</bean>
[/sourcecode]


please note that I am using Cassandra 1.0 and hect 1.0 now. if you are using some other versions, you might need to make sure all the referred classes are in the package.

After you have the template then you can use it as other spring template.

No comments: