use of com.amazonaws.services.kinesis.model.PutRecordRequest in project apex-malhar by apache.
the class KinesisTestProducer method run.
@Override
public void run() {
if (records == null) {
generateRecords();
} else {
for (String msg : records) {
PutRecordRequest putRecordRequest = new PutRecordRequest();
putRecordRequest.setStreamName(streamName);
putRecordRequest.setData(ByteBuffer.wrap(msg.getBytes()));
putRecordRequest.setPartitionKey(msg);
client.putRecord(putRecordRequest);
}
}
}
use of com.amazonaws.services.kinesis.model.PutRecordRequest in project camel by apache.
the class KinesisProducer method createRequest.
private PutRecordRequest createRequest(Exchange exchange) {
ByteBuffer body = exchange.getIn().getBody(ByteBuffer.class);
Object partitionKey = exchange.getIn().getHeader(KinesisConstants.PARTITION_KEY);
Object sequenceNumber = exchange.getIn().getHeader(KinesisConstants.SEQUENCE_NUMBER);
PutRecordRequest putRecordRequest = new PutRecordRequest();
putRecordRequest.setData(body);
putRecordRequest.setStreamName(getEndpoint().getStreamName());
putRecordRequest.setPartitionKey(partitionKey.toString());
if (sequenceNumber != null) {
putRecordRequest.setSequenceNumberForOrdering(sequenceNumber.toString());
}
return putRecordRequest;
}
use of com.amazonaws.services.kinesis.model.PutRecordRequest in project camel by apache.
the class KinesisProducer method process.
@Override
public void process(Exchange exchange) throws Exception {
PutRecordRequest request = createRequest(exchange);
PutRecordResult putRecordResult = getEndpoint().getClient().putRecord(request);
Message message = getMessageForResponse(exchange);
message.setHeader(KinesisConstants.SEQUENCE_NUMBER, putRecordResult.getSequenceNumber());
message.setHeader(KinesisConstants.SHARD_ID, putRecordResult.getShardId());
}
use of com.amazonaws.services.kinesis.model.PutRecordRequest in project camel by apache.
the class KinesisProducerTest method shouldPutRecordInRightStreamWhenProcessingExchange.
@Test
public void shouldPutRecordInRightStreamWhenProcessingExchange() throws Exception {
kinesisProducer.process(exchange);
ArgumentCaptor<PutRecordRequest> capture = ArgumentCaptor.forClass(PutRecordRequest.class);
verify(kinesisClient).putRecord(capture.capture());
PutRecordRequest request = capture.getValue();
ByteBuffer byteBuffer = request.getData();
byte[] actualArray = byteBuffer.array();
byte[] sampleArray = SAMPLE_BUFFER.array();
assertEquals(sampleArray, actualArray);
assertEquals(STREAM_NAME, request.getStreamName());
}
use of com.amazonaws.services.kinesis.model.PutRecordRequest in project camel by apache.
the class KinesisProducerTest method shouldHaveProperHeadersWhenSending.
@Test
public void shouldHaveProperHeadersWhenSending() throws Exception {
String seqNoForOrdering = "1851";
when(inMessage.getHeader(KinesisConstants.SEQUENCE_NUMBER)).thenReturn(seqNoForOrdering);
kinesisProducer.process(exchange);
ArgumentCaptor<PutRecordRequest> capture = ArgumentCaptor.forClass(PutRecordRequest.class);
verify(kinesisClient).putRecord(capture.capture());
PutRecordRequest request = capture.getValue();
assertEquals(PARTITION_KEY, request.getPartitionKey());
assertEquals(seqNoForOrdering, request.getSequenceNumberForOrdering());
verify(outMessage).setHeader(KinesisConstants.SEQUENCE_NUMBER, SEQUENCE_NUMBER);
verify(outMessage).setHeader(KinesisConstants.SHARD_ID, SHARD_ID);
}
Aggregations