Search in sources :

Example 61 with SimpleStringSchema

use of org.apache.flink.api.common.serialization.SimpleStringSchema in project flink by apache.

the class SinkIntoKinesis method main.

public static void main(String[] args) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.enableCheckpointing(10_000);
    DataStream<String> fromGen = env.fromSequence(1, 10_000_000L).map(Object::toString).returns(String.class).map(data -> mapper.writeValueAsString(ImmutableMap.of("data", data)));
    Properties sinkProperties = new Properties();
    sinkProperties.put(AWSConfigConstants.AWS_REGION, "your-region-here");
    KinesisDataStreamsSink<String> kdsSink = KinesisDataStreamsSink.<String>builder().setSerializationSchema(new SimpleStringSchema()).setPartitionKeyGenerator(element -> String.valueOf(element.hashCode())).setStreamName("your-stream-name").setMaxBatchSize(20).setKinesisClientProperties(sinkProperties).build();
    fromGen.sinkTo(kdsSink);
    env.execute("KDS Async Sink Example Program");
}
Also used : SimpleStringSchema(org.apache.flink.api.common.serialization.SimpleStringSchema) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Properties(java.util.Properties) ObjectMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper)

Example 62 with SimpleStringSchema

use of org.apache.flink.api.common.serialization.SimpleStringSchema in project flink by apache.

the class KinesisFirehoseSinkElementConverterTest method elementConverterUsesProvidedSchemaToSerializeRecord.

@Test
public void elementConverterUsesProvidedSchemaToSerializeRecord() {
    ElementConverter<String, Record> elementConverter = KinesisFirehoseSinkElementConverter.<String>builder().setSerializationSchema(new SimpleStringSchema()).build();
    String testString = "{many hands make light work;";
    Record serializedRecord = elementConverter.apply(testString, null);
    byte[] serializedString = (new SimpleStringSchema()).serialize(testString);
    assertThat(serializedRecord.data()).isEqualTo(SdkBytes.fromByteArray(serializedString));
}
Also used : SimpleStringSchema(org.apache.flink.api.common.serialization.SimpleStringSchema) Record(software.amazon.awssdk.services.firehose.model.Record) Test(org.junit.Test)

Example 63 with SimpleStringSchema

use of org.apache.flink.api.common.serialization.SimpleStringSchema in project flink by apache.

the class KinesisFirehoseSinkTest method firehoseSinkFailsWithAppropriateMessageWhenInitialConditionsAreMisconfigured.

private void firehoseSinkFailsWithAppropriateMessageWhenInitialConditionsAreMisconfigured(Properties properties, String errorMessage) {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    KinesisFirehoseSink<String> kdsSink = KinesisFirehoseSink.<String>builder().setSerializationSchema(new SimpleStringSchema()).setDeliveryStreamName("non-existent-stream").setMaxBatchSize(1).setFirehoseClientProperties(properties).build();
    KinesisFirehoseTestUtils.getSampleDataGenerator(env, 10).sinkTo(kdsSink);
    Assertions.assertThatExceptionOfType(JobExecutionException.class).isThrownBy(() -> env.execute("Integration Test")).havingCause().havingCause().withMessageContaining(errorMessage);
}
Also used : SimpleStringSchema(org.apache.flink.api.common.serialization.SimpleStringSchema) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)

Aggregations

SimpleStringSchema (org.apache.flink.api.common.serialization.SimpleStringSchema)63 Test (org.junit.Test)35 Properties (java.util.Properties)30 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)20 CheckedThread (org.apache.flink.core.testutils.CheckedThread)13 StreamShardHandle (org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle)13 Shard (com.amazonaws.services.kinesis.model.Shard)11 ArrayList (java.util.ArrayList)11 KinesisStreamShardState (org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShardState)11 TestableKinesisDataFetcher (org.apache.flink.streaming.connectors.kinesis.testutils.TestableKinesisDataFetcher)11 LinkedList (java.util.LinkedList)9 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)9 HashMap (java.util.HashMap)8 StreamShardMetadata (org.apache.flink.streaming.connectors.kinesis.model.StreamShardMetadata)7 OneInputStreamOperatorTestHarness (org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness)7 Map (java.util.Map)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)6 Matchers.anyString (org.mockito.Matchers.anyString)6 SequenceNumberRange (com.amazonaws.services.kinesis.model.SequenceNumberRange)5