我正在尝试订阅目录以进行通知。但是找不到符号"然后是#34;请帮忙。
// subscription to notifications
CompletionStage<NotificationSubscriptionControl> controlStage =
queryApi.subscribeToNotifications(consumerSettings)
.thenApply(subscription -> {
subscription
.notifications()
.runWith(Sink.foreach(notification ->
// this callback is called each time a new batch publication happens in catalog
System.out.printf("catalog %s has a new version %d\n", catalogHrn, notification.getCatalogVersion())
), myMaterializer);
return subscription.subscriptionControl();
});
[错误]编译错误:[INFO] ----------------------------------- -------------------------- [ERROR] Main.java:[41,25]找不到符号符号:方法 thenApply((下标...;})location:interface org.apache.flink.streaming.api.functions.source.SourceFunction [错误] Main.java:[44,65]包akka.stream.javadsl不存在 [错误] Main.java:[47,40]找不到符号符号:变量 myMaterializer
答案 0 :(得分:1)
根据您的编译错误,您似乎正在尝试在Flink应用程序中订阅通知。 Flink数据客户端queryApi返回SourceFunction,而不是CompletionStage。您可以像这样使用它:
StreamExecutionEnvironment
.getExecutionEnvironment()
.addSource(
query.subscribeToNotifications(
new NotificationConsumerSettings(
"my-notification-consumer-group-1"
)
)
)
.addSink(
notification - > System.out.printf(
"catalog %s has a new version %d\n",
STREAMING_INPUT_CATALOG_HRN,
notification
.getCatalogVersion()
)
);
答案 1 :(得分:0)
如果subscribeToNotifications是一个阻止函数,则可以将其包装在CompletableFuture的completedFuture方法中。
CompletionStage<NotificationSubscriptionControl> controlStage =
CompletableFuture.completedFuture(queryApi.subscribeToNotifications(consumerSettings))
.thenApply(
subscription -> {
subscription
.notifications()
.runWith(
Sink.foreach(
notification ->
// this callback is called each time a new batch publication
// happens in catalog
System.out.printf(
"catalog %s has a new version %d\n",
catalogHrn, notification.getCatalogVersion())),
myMaterializer);
return subscription.subscriptionControl();
});