Riak and Spring

Mark Richard Thomas mark.thomas at equifax.com
Wed Aug 6 04:50:22 EDT 2014


1)      Create a riakClient bean (applicationContext.xml)

       <bean id="riakClient" class="com.basho.riak.client.RiakFactory"
              <constructor-arg ref="HTTPClientConfigFactory" />

2)      create a HTTPClientConfigFactory bean in which you can specify the host and port:

package com.webapp.util;

import org.apache.http.client.HttpClient;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.basho.riak.client.raw.http.HTTPClientConfig;

public class HTTPClientConfigFactory implements FactoryBean<HTTPClientConfig> {

                private String host;
                private int port;

                HttpClient httpClient;

                public HTTPClientConfig getObject() throws Exception {
                                return new HTTPClientConfig.Builder().withHttpClient(httpClient)

                public Class<?> getObjectType() {
                                return HTTPClientConfig.class;

                public boolean isSingleton() {
                                return true;

                protected void finalize() throws Throwable {

3)      Use the RiakClient within a service:

       private IRiakClient client;

       public Name getName(String sname) {
              try {
                     Name name = client.fetchBucket(NAMEBUCKET).execute()
                                  .fetch(sname, Name.class).execute();
                     if (name == null) {
                           throw new ResourceNotFoundException(sname);
                     return name;
              } catch (UnresolvedConflictException | RiakRetryFailedException
                           | ConversionException e) {
                     throw new ServiceUnavailableException(sname);

Mark Thomas | Software Engineer | Equifax UK

p:   +44 (0)208 941 0573
m:  +44 (0)7908 798 270
e:   mark.thomas at equifax.com<mailto:mark.thomas at equifax.com>

Equifax Ltd, Capital House, 25 Chapel Street, London, NW1 5DS

From: riak-users [mailto:riak-users-bounces at lists.basho.com] On Behalf Of Simon Hartley
Sent: 30 July 2014 15:37
To: riak-users at lists.basho.com
Subject: [IE]:Riak and Spring


I'm looking at using a Riak backend in a new component.

My current client is a Spring shop. I'm not all that knowledgable about the intricaies of Spring , so this question many not make sense, but I am hoping to integrate Riak in a Spring friendly way.

I was looking at the spring-projects/spring-data-keyvalue<https://github.com/spring-projects/spring-data-keyvalue> project, but that's been deprecated in favour of spring-projects/spring-data-riak<https://github.com/spring-projects/spring-data-riak> which is empty.

Does anyone know of a Spring-Riak integration project that is high quality and currently active -  preferably with excellent documentation and examples ;)


Confidentiality: The contents of this e-mail and any attachments transmitted with it are intended to be confidential to the intended recipient; and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error. This e-mail is sent by a William Hill PLC group company. The William Hill group companies include, among others, William Hill PLC (registered number 4212563), William Hill Organization Limited (registered number 278208), William Hill US HoldCo Inc, WHG (International) Limited (registered number 99191) and WHG Trading Limited (registered number 101439). Each of William Hill PLC, William Hill Organization Limited is registered in England and Wales and has its registered office at Greenside House, 50 Station Road, Wood Green, London N22 7TP. William Hill U.S. HoldCo, Inc. is 160 Greentree Drive, Suite 101, Dover 19904, Kent, Delaware, United States of America. Each of WHG (International) Limited and WHG Trading Limited is registered in Gibraltar and has its registered office at 6/1 Waterport Place, Gibraltar. Unless specifically indicated otherwise, the contents of this e-mail are subject to contract; and are not an official statement, and do not necessarily represent the views, of William Hill PLC, its subsidiaries or affiliated companies. Please note that neither William Hill PLC, nor its subsidiaries and affiliated companies can accept any responsibility for any viruses contained within this e-mail and it is your responsibility to scan any emails and their attachments. William Hill PLC, its subsidiaries and affiliated companies may monitor e-mail traffic data and also the content of e-mails for effective operation of the e-mail system, or for security, purposes..
Equifax Limited is registered in England with Registered No. 2425920. Registered Office: Capital House, 25 Chapel Street, London NW1 5DS. Equifax Limited is authorised and regulated by the Financial Conduct Authority.
Equifax Touchstone Limited is registered in Scotland with Registered No. SC113401. Registered Office: 54 Deerdykes View, Westfield Park, Cumbernauld G68 9HN.
Equifax Commercial Services Limited is registered in the Republic of Ireland with Registered No. 215393. Registered Office: IDA Business & Technology Park, Rosslare Road, Drinagh, Wexford.

This message contains information from Equifax which may be confidential and privileged. If you are not an intended recipient, please refrain from any disclosure, copying, distribution or use of this information and note that such actions are prohibited. If you have received this transmission in error, please notify by e-mail postmaster at equifax.com<mailto:postmaster at equifax.com>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20140806/f5ca1a75/attachment.html>

More information about the riak-users mailing list