我想在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
内部执行相同的操作?