Search in sources :

Example 6 with Record

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));
}
Also used : RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) UserRecord(com.amazonaws.services.kinesis.clientlibrary.types.UserRecord) UserRecord(com.amazonaws.services.kinesis.clientlibrary.types.UserRecord) Record(software.amazon.awssdk.services.kinesis.model.Record) KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) Date(java.util.Date) TestConsumer(org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils.TestConsumer) Test(org.junit.Test)

Example 7 with Record

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;
}
Also used : COMPLETE(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.COMPLETE) Date(java.util.Date) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff) LoggerFactory(org.slf4j.LoggerFactory) RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) StartingPosition(org.apache.flink.streaming.connectors.kinesis.model.StartingPosition) FanOutSubscriberInterruptedException(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.FanOutSubscriberInterruptedException) ArrayList(java.util.ArrayList) FanOutSubscriberException(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.FanOutSubscriberException) SubscribeToShardEvent(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber) Nonnull(javax.annotation.Nonnull) StartingPosition.builder(software.amazon.awssdk.services.kinesis.model.StartingPosition.builder) KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) INCOMPLETE(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.INCOMPLETE) ResourceNotFoundException(software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException) Logger(org.slf4j.Logger) StreamShardHandle(org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle) RecoverableFanOutSubscriberException(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.RecoverableFanOutSubscriberException) Preconditions(org.apache.flink.util.Preconditions) Consumer(java.util.function.Consumer) RecordBatch(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch) List(java.util.List) EncryptionType(software.amazon.awssdk.services.kinesis.model.EncryptionType) Record(software.amazon.awssdk.services.kinesis.model.Record) CANCELLED(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.CANCELLED) Internal(org.apache.flink.annotation.Internal) RecordBatch(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber) SubscribeToShardEvent(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent)

Example 8 with Record

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;
}
Also used : EncryptionType(software.amazon.awssdk.services.kinesis.model.EncryptionType) Record(software.amazon.awssdk.services.kinesis.model.Record) Date(java.util.Date)

Aggregations

Record (software.amazon.awssdk.services.kinesis.model.Record)8 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 List (java.util.List)2 Read (org.apache.beam.sdk.io.aws2.kinesis.KinesisIO.Read)2 RecordPublisher (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher)2 KinesisProxyV2Interface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface)2 Test (org.junit.Test)2 EncryptionType (software.amazon.awssdk.services.kinesis.model.EncryptionType)2 GetRecordsResponse (software.amazon.awssdk.services.kinesis.model.GetRecordsResponse)2 UserRecord (com.amazonaws.services.kinesis.clientlibrary.types.UserRecord)1 URI (java.net.URI)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 BiFunction (java.util.function.BiFunction)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Function.identity (java.util.function.Function.identity)1 IntFunction (java.util.function.IntFunction)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream.range (java.util.stream.IntStream.range)1