use of software.amazon.awssdk.services.kinesis.model.Record in project flink by apache.
the class FanOutRecordPublisherTest method testToSdkV1Records.
@Test
public void testToSdkV1Records() throws Exception {
Date now = new Date();
byte[] data = new byte[] { 0, 1, 2, 3 };
Record record = Record.builder().approximateArrivalTimestamp(now.toInstant()).partitionKey("pk").sequenceNumber("sn").data(SdkBytes.fromByteArray(data)).build();
KinesisProxyV2Interface kinesis = singletonShard(createSubscribeToShardEvent(record));
RecordPublisher publisher = createRecordPublisher(kinesis, latest());
TestConsumer consumer = new TestConsumer();
publisher.run(consumer);
UserRecord actual = consumer.getRecordBatches().get(0).getDeaggregatedRecords().get(0);
assertFalse(actual.isAggregated());
assertEquals(now, actual.getApproximateArrivalTimestamp());
assertEquals("sn", actual.getSequenceNumber());
assertEquals("pk", actual.getPartitionKey());
assertThat(toByteArray(actual.getData()), Matchers.equalTo(data));
}
use of software.amazon.awssdk.services.kinesis.model.Record in project flink by apache.
the class FanOutRecordPublisher method run.
@Override
public RecordPublisherRunResult run(final RecordBatchConsumer recordConsumer) throws InterruptedException {
LOG.info("Running fan out record publisher on {}::{} from {} - {}", subscribedShard.getStreamName(), subscribedShard.getShard().getShardId(), nextStartingPosition.getShardIteratorType(), nextStartingPosition.getStartingMarker());
Consumer<SubscribeToShardEvent> eventConsumer = event -> {
RecordBatch recordBatch = new RecordBatch(toSdkV1Records(event.records()), subscribedShard, event.millisBehindLatest());
SequenceNumber sequenceNumber = recordConsumer.accept(recordBatch);
nextStartingPosition = StartingPosition.continueFromSequenceNumber(sequenceNumber);
};
RecordPublisherRunResult result = runWithBackoff(eventConsumer);
LOG.info("Subscription expired {}::{}, with status {}", subscribedShard.getStreamName(), subscribedShard.getShard().getShardId(), result);
return result;
}
use of software.amazon.awssdk.services.kinesis.model.Record in project flink by apache.
the class FanOutRecordPublisher method toSdkV1Record.
private com.amazonaws.services.kinesis.model.Record toSdkV1Record(@Nonnull final Record record) {
final com.amazonaws.services.kinesis.model.Record recordV1 = new com.amazonaws.services.kinesis.model.Record().withData(record.data().asByteBuffer()).withSequenceNumber(record.sequenceNumber()).withPartitionKey(record.partitionKey()).withApproximateArrivalTimestamp(new Date(record.approximateArrivalTimestamp().toEpochMilli()));
EncryptionType encryptionType = record.encryptionType();
if (encryptionType != null) {
recordV1.withEncryptionType(encryptionType.name());
}
return recordV1;
}
Aggregations