Riak 2.0 java client Usage

hotmail.kwyto kwyto at hotmail.com
Tue Jun 3 00:38:16 EDT 2014


Hi, 

I have tried using the java client for Riak 2.0 without success.  I have created 2 buckets types:  one has properties {allow_mult:true, datatype:map} and the other one {allow_mult:true, last_write_wins:true}.  Below are the two approaches I tried.  The first attempts to save a Map in map-device-usage, the second one tries to saves an object under default.  In both occasions I never get an error but nothing is stored in Riak.  After a few minutes of the application running I just stop the app.  
Both bucket-types are active.  Im using leveled as backend.  Im writing to a cluster of 1 node just for the sake of prototyping.  The client was built from branch develop.  
 
questions: 
- Am I using the client correctly?  
- Obviously something is going wrong, so where are the errors, or any logs for that matter? 

Any help or insight would be much appreciated. 
RiakClient riakClient() {
    RiakClient client = null;
    try {
      RiakNode node = new RiakNode.Builder()
          .withMaxConnections(riakPoolSize)
          .withMinConnections(riakInitialPoolSize)
          .withRemotePort(riakPort)
          .withRemoteAddress(riakHost)
          .build();
      RiakCluster cluster = new RiakCluster.Builder(node)
          .withExecutor(Executors.newScheduledThreadPool(5))
          .build();
      client = new RiakClient(cluster);
    } catch (UnknownHostException e) {
      LOG.error("Riak node was not created", e);
    }
    return client;
  }



———————————————————————————————————

        String deviceKey = RiakUtils.buildDeviceKey(e.getSourceId(), e.getCreatedAt());
        String eventKey = RiakUtils.buildEventKey(e.getType(), e.getCreatedAt());

        Location deviceMap = new Location(bucketName)
            .setBucketType(bucketType)
            .setKey(deviceKey);

        // im not sure if this is the way to do it //
        MapUpdate eventMap = new MapUpdate()
            .add("id", new RegisterUpdate(BinaryValue.create(eventKey).getValue()))
            .add("source", new RegisterUpdate(BinaryValue.create(e.getSource()).getValue()))
    .add("sourceId", new RegisterUpdate(BinaryValue.create(e.getSourceId().toString()).getValue()))
            .add("sourceTypeId", new RegisterUpdate(BinaryValue.create(e.getSourceTypeId().toString()).getValue()))
            .add("created_at", new RegisterUpdate(BinaryValue.create(e.getCreatedAt().toString()).getValue()))
            .add("recorded_at", new RegisterUpdate(BinaryValue.create(DateTime.now().toString()).getValue()))
            .add("data", new RegisterUpdate(BinaryValue.create(e.getData().toString()).getValue()));
        UpdateMap update = new UpdateMap.Builder(deviceMap, eventMap).build();

client.executeAsync(update);


———————————————————————————————————

RiakObject event = null;
        try {
          event = new RiakObject().setContentType(Constants.CTYPE_JSON)
              .setValue(BinaryValue.create(mapper.writeValueAsBytes(e)));
        } catch (JsonProcessingException jpe) {
          LOG.warn("Could not create RiakObject[content={}]", e, jpe);
        }
 Location deviceMap = new Location(bucketName)
            .setKey(deviceKey);

        // this is another way // 
        StoreValue storeValue = new StoreValue.Builder(event)
            .withLocation(deviceMap)
            .build();

        try {
          StoreValue.Response resp = client.executeAsync(storeValue).get();
          System.out.println(resp);
        } catch (InterruptedException e1) {
          e1.printStackTrace();
        }
 

Regards,
-- 
yoandy terradas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20140602/6cbc3087/attachment.html>


More information about the riak-users mailing list