Search in sources :

Example 1 with PutRecordRequest

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);
        }
    }
}
Also used : PutRecordRequest(com.amazonaws.services.kinesis.model.PutRecordRequest)

Example 2 with 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;
}
Also used : PutRecordRequest(com.amazonaws.services.kinesis.model.PutRecordRequest) ByteBuffer(java.nio.ByteBuffer)

Example 3 with 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());
}
Also used : PutRecordResult(com.amazonaws.services.kinesis.model.PutRecordResult) Message(org.apache.camel.Message) PutRecordRequest(com.amazonaws.services.kinesis.model.PutRecordRequest)

Example 4 with PutRecordRequest

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());
}
Also used : PutRecordRequest(com.amazonaws.services.kinesis.model.PutRecordRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with PutRecordRequest

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);
}
Also used : PutRecordRequest(com.amazonaws.services.kinesis.model.PutRecordRequest) Test(org.junit.Test)

Aggregations

PutRecordRequest (com.amazonaws.services.kinesis.model.PutRecordRequest)6 ByteBuffer (java.nio.ByteBuffer)2 Test (org.junit.Test)2 AmazonClientException (com.amazonaws.AmazonClientException)1 PutRecordResult (com.amazonaws.services.kinesis.model.PutRecordResult)1 Message (org.apache.camel.Message)1