Search in sources :

Example 1 with JsonDataWithSchema

use of com.amazonaws.services.schemaregistry.serializers.json.JsonDataWithSchema 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 JsonDataWithSchema

use of com.amazonaws.services.schemaregistry.serializers.json.JsonDataWithSchema in project flink by apache.

the class GlueSchemaRegistryJsonKinesisITCase method testGSRJsonGenericFormatWithFlink.

@Test
public void testGSRJsonGenericFormatWithFlink() throws Exception {
    List<JsonDataWithSchema> messages = getGenericRecords();
    for (JsonDataWithSchema msg : messages) {
        kinesisClient.sendMessage(msg.getSchema(), INPUT_STREAM, msg);
    }
    log.info("generated records");
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    DataStream<JsonDataWithSchema> input = env.addSource(createSource());
    input.addSink(createSink());
    env.executeAsync();
    Deadline deadline = Deadline.fromNow(Duration.ofSeconds(60));
    List<Object> results = kinesisClient.readAllMessages(OUTPUT_STREAM);
    while (deadline.hasTimeLeft() && results.size() < messages.size()) {
        log.info("waiting for results..");
        Thread.sleep(1000);
        results = kinesisClient.readAllMessages(OUTPUT_STREAM);
    }
    log.info("results: {}", results);
    assertThat(results).containsExactlyInAnyOrderElementsOf(messages);
}
Also used : Deadline(org.apache.flink.api.common.time.Deadline) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JsonDataWithSchema(com.amazonaws.services.schemaregistry.serializers.json.JsonDataWithSchema) Test(org.junit.Test)

Aggregations

JsonDataWithSchema (com.amazonaws.services.schemaregistry.serializers.json.JsonDataWithSchema)2 Properties (java.util.Properties)1 Deadline (org.apache.flink.api.common.time.Deadline)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 FlinkKinesisConsumer (org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer)1 Test (org.junit.Test)1