List of usage examples for com.amazonaws.services.kinesis.model PutRecordsRequestEntry setExplicitHashKey
public void setExplicitHashKey(String explicitHashKey)
The hash value used to determine explicitly the shard that the data record is assigned to by overriding the partition key hash.
From source file:com.srotya.flume.kinesis.sink.KinesisSink.java
License:Apache License
@Override public Status process() throws EventDeliveryException { Status status = Status.READY;/*from w w w .j av a 2 s . c om*/ Channel ch = getChannel(); Transaction tx = ch.getTransaction(); tx.begin(); try { PutRecordsRequest request = new PutRecordsRequest(); List<PutRecordsRequestEntry> records = new ArrayList<>(); for (int i = 0; i < putSize; i++) { Event event = ch.take(); PutRecordsRequestEntry entry = new PutRecordsRequestEntry(); if (partitionKey != null) { entry.setPartitionKey(event.getHeaders().get(partitionKey)); } else { entry.setPartitionKey(String.format("partitionKey-%d", i)); } if (hashKey != null) { entry.setExplicitHashKey(event.getHeaders().get(hashKey)); } entry.setData(serializer.serialize(event)); records.add(entry); } request.setRecords(records); request.setStreamName(streamName); client.putRecords(request); tx.commit(); } catch (Throwable e) { e.printStackTrace(); tx.rollback(); status = Status.BACKOFF; } finally { try { tx.close(); } catch (Exception e) { e.printStackTrace(); } } return status; }