Riak and Spring

Simon Hartley Simon.Hartley at williamhill.com
Wed Aug 6 05:06:53 EDT 2014


Hi,

Thanks, for your suggestions.

I've done something similar, but injected the client config directly into the client bean in the application configuration (not via the HTTPClientConfigFactory). E.g:

@ComponentScan
@EnableAutoConfiguration
public class Application {

    @Value( "${riak.pool.host}" ) private String poolHost;
    @Value( "${riak.pool.port}" ) private int poolPort;
    @Value( "${riak.pool.timeout.connection}" ) private long poolTimeoutConnection;
    @Value( "${riak.pool.timeout.idle}" ) private long poolTimeoutIdle;
    @Value( "${riak.pool.timeout.request}" ) private int poolTimeoutRequest;
    @Value( "${riak.pool.buffersize}" ) private int poolBufferSize;

       @Bean
    public static PropertyPlaceholderConfigurer properties(){
      PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
      ClassPathResource[] resources = new ClassPathResource[ ]{ new ClassPathResource( "app.properties" ) };
      ppc.setLocations(resources);
      ppc.setIgnoreUnresolvablePlaceholders(true);
      return ppc;
    }

       @Bean
       @Scope("singleton")
       IRiakClient riakClient() throws Exception{

              //create a single client connection configuration using the property file values
              Configuration config = (new PBClientConfig.Builder())
                                                                            .withConnectionTimeoutMillis(poolTimeoutConnection)
                                                                            .withIdleConnectionTTLMillis(poolTimeoutIdle)
                                                                            .withRequestTimeoutMillis(poolTimeoutRequest)
                                                                           .withHost(poolHost)
                                                                           .withPort(poolPort)
                                                                            .withSocketBufferSizeKb(poolBufferSize)
                                                                           .build();

              //create the singleton Riak client using the connection configuration
              IRiakClient client = RiakFactory.newClient(config);

              return client;
       }

    public static void main(String[] args) {

        SpringApplication.run(Application.class, args);
    }
}

I'm not aware of any obvious benefits of one method over the other. If anyone can enlighten me please do so :)

Thanks,

Simon.

From: Mark Richard Thomas [mailto:mark.thomas at equifax.com]
Sent: 06 August 2014 09:50
To: Simon Hartley; riak-users at lists.basho.com
Subject: RE: Riak and Spring

Hello


1)      Create a riakClient bean (applicationContext.xml)

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


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;

@Component
public class HTTPClientConfigFactory implements FactoryBean<HTTPClientConfig> {

                @Value("${${environment}.host}")
                private String host;
                @Value("${${environment}.port}")
                private int port;

                @Autowired
                HttpClient httpClient;

                public HTTPClientConfig getObject() throws Exception {
                                return new HTTPClientConfig.Builder().withHttpClient(httpClient)
                                                                .withHost(host).withPort(port).build();
                }

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

                @Override
                public boolean isSingleton() {
                                return true;
                }

                @Override
                protected void finalize() throws Throwable {
                                httpClient.getConnectionManager().shutdown();
                }
}


3)      Use the RiakClient within a service:

       @Autowired
       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<mailto:riak-users at lists.basho.com>
Subject: [IE]:Riak and Spring

Hi,

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 ;)

Thanks,

Simon.
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>.
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..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20140806/c56cd3b3/attachment.html>


More information about the riak-users mailing list