1

我正在尝试订阅目录以获取通知。但找不到符号“thenAppy”。请帮忙。

// 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();
        });

[错误] 编译错误:[信息] ----------------------------------------- -------------------- [错误] Main.java:[41,25] 找不到符号符号:方法 thenApply((subscript...; }) 位置:接口 org.apache.flink.streaming.api.functions.source.SourceFunction [错误] Main.java:[44,65] 包 akka.stream.javadsl 不存在 [错误] Main.java:[47,40] 不能查找符号符号:变量 myMaterializer

4

2 回答 2

2

根据您的编译错误,您似乎正在尝试订阅 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()
        )
    );
于 2018-06-20T15:41:34.577 回答
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();
                });
于 2018-07-01T12:15:07.813 回答