Flink:如何在ProcessFunction中使用Flink异步I / O执行异步Cassandra查找?

时间:2018-07-09 08:35:01

标签: java cassandra apache-flink

我想在ProcessFunction中使用Flink asynchronous I/O执行Cassandra查找。现在,当我在main方法中将结果作为DataStream返回时,它可以正常工作,就像这样-

public static void main(String args[]) throws Exception {
    ConnectionProps props = new ConnectionProps(args, "props.properties");

    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

    Tuple2<String, String> sample1 = new Tuple2<>("flink", "flink-user-1");
    Tuple2<String, String> sample2 = new Tuple2<>("flink", "flink-user-2");

    DataStream<Tuple2<String, String>> samples = env.fromElements(sample1, sample2);

    //Result will be in the form of <query, resultset.toString()>
    DataStream<Tuple2<String, String>> lookupResult = AsyncDataStream
                .orderedWait(samples, new AsyncCassandraReader(props), 
                             5, TimeUnit.SECONDS, 
                             props.getAsyncIoCapacity());

    lookupResult.print();
}

AsyncCassandraReader有一个asyncInvoke方法,该方法根据传递的DataStream<Tuple2<String, String>>进行Cassandra查找。

如何在ProcessFunction内部执行相同的操作?

0 个答案:

没有答案