Search in sources :

Example 1 with FlinkKinesisConsumer

use of org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer in project flink by apache.

the class GlueSchemaRegistryJsonKinesisITCase method createSource.

private FlinkKinesisConsumer<JsonDataWithSchema> createSource() {
    Properties properties = KINESALITE.getContainerProperties();
    properties.setProperty(STREAM_INITIAL_POSITION, ConsumerConfigConstants.InitialPosition.TRIM_HORIZON.name());
    return new FlinkKinesisConsumer<>(INPUT_STREAM, new GlueSchemaRegistryJsonDeserializationSchema<>(JsonDataWithSchema.class, INPUT_STREAM, getConfigs()), properties);
}
Also used : FlinkKinesisConsumer(org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer) Properties(java.util.Properties) JsonDataWithSchema(com.amazonaws.services.schemaregistry.serializers.json.JsonDataWithSchema)

Example 2 with FlinkKinesisConsumer

use of org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer in project flink by apache.

the class KinesisExample method main.

public static void main(String[] args) throws Exception {
    // parse input arguments
    final ParameterTool parameterTool = ParameterTool.fromArgs(args);
    StreamExecutionEnvironment env = KafkaExampleUtil.prepareExecutionEnv(parameterTool);
    String inputStream = parameterTool.getRequired("input-stream");
    String outputStream = parameterTool.getRequired("output-stream");
    FlinkKinesisConsumer<KafkaEvent> consumer = new FlinkKinesisConsumer<>(inputStream, new KafkaEventSchema(), parameterTool.getProperties());
    consumer.setPeriodicWatermarkAssigner(new CustomWatermarkExtractor());
    Properties producerProperties = new Properties(parameterTool.getProperties());
    // producer needs region even when URL is specified
    producerProperties.putIfAbsent(ConsumerConfigConstants.AWS_REGION, "us-east-1");
    // test driver does not deaggregate
    producerProperties.putIfAbsent("AggregationEnabled", String.valueOf(false));
    // KPL does not recognize endpoint URL..
    String kinesisUrl = producerProperties.getProperty(ConsumerConfigConstants.AWS_ENDPOINT);
    if (kinesisUrl != null) {
        URL url = new URL(kinesisUrl);
        producerProperties.put("KinesisEndpoint", url.getHost());
        producerProperties.put("KinesisPort", Integer.toString(url.getPort()));
        producerProperties.put("VerifyCertificate", "false");
    }
    FlinkKinesisProducer<KafkaEvent> producer = new FlinkKinesisProducer<>(new KafkaEventSchema(), producerProperties);
    producer.setDefaultStream(outputStream);
    producer.setDefaultPartition("fakePartition");
    DataStream<KafkaEvent> input = env.addSource(consumer).keyBy("word").map(new RollingAdditionMapper());
    input.addSink(producer);
    env.execute();
}
Also used : ParameterTool(org.apache.flink.api.java.utils.ParameterTool) RollingAdditionMapper(org.apache.flink.streaming.kafka.test.base.RollingAdditionMapper) Properties(java.util.Properties) URL(java.net.URL) FlinkKinesisConsumer(org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer) FlinkKinesisProducer(org.apache.flink.streaming.connectors.kinesis.FlinkKinesisProducer) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) KafkaEvent(org.apache.flink.streaming.kafka.test.base.KafkaEvent) KafkaEventSchema(org.apache.flink.streaming.kafka.test.base.KafkaEventSchema) CustomWatermarkExtractor(org.apache.flink.streaming.kafka.test.base.CustomWatermarkExtractor)

Example 3 with FlinkKinesisConsumer

use of org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer in project flink by apache.

the class GlueSchemaRegistryAvroKinesisITCase method createSource.

private FlinkKinesisConsumer<GenericRecord> createSource() throws Exception {
    Properties properties = KINESALITE.getContainerProperties();
    properties.setProperty(STREAM_INITIAL_POSITION, ConsumerConfigConstants.InitialPosition.TRIM_HORIZON.name());
    return new FlinkKinesisConsumer<>(INPUT_STREAM, GlueSchemaRegistryAvroDeserializationSchema.forGeneric(getSchema(), getConfigs()), properties);
}
Also used : FlinkKinesisConsumer(org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)3 FlinkKinesisConsumer (org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer)3 JsonDataWithSchema (com.amazonaws.services.schemaregistry.serializers.json.JsonDataWithSchema)1 URL (java.net.URL)1 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 FlinkKinesisProducer (org.apache.flink.streaming.connectors.kinesis.FlinkKinesisProducer)1 CustomWatermarkExtractor (org.apache.flink.streaming.kafka.test.base.CustomWatermarkExtractor)1 KafkaEvent (org.apache.flink.streaming.kafka.test.base.KafkaEvent)1 KafkaEventSchema (org.apache.flink.streaming.kafka.test.base.KafkaEventSchema)1 RollingAdditionMapper (org.apache.flink.streaming.kafka.test.base.RollingAdditionMapper)1