Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 消费来自谷歌Pubsub的消息并将其发布到卡夫卡_Google Cloud Platform_Apache Flink_Apache Beam_Google Cloud Pubsub_Apache Beam Kafkaio - Fatal编程技术网

Google cloud platform 消费来自谷歌Pubsub的消息并将其发布到卡夫卡

Google cloud platform 消费来自谷歌Pubsub的消息并将其发布到卡夫卡,google-cloud-platform,apache-flink,apache-beam,google-cloud-pubsub,apache-beam-kafkaio,Google Cloud Platform,Apache Flink,Apache Beam,Google Cloud Pubsub,Apache Beam Kafkaio,我正在尝试使用同步拉API使用GooglePubSub消息。这在Apache Beam Google PubSub IO连接器库中提供。 我想用KafkaIO将已消费的消息写入Kafka。我想使用FlinkRunner来执行作业,因为我们在GCP之外运行这个应用程序 我面临的问题是,在GCP PubSub中,消费的消息没有得到确认。我已确认本地Kafka实例已使用来自GCP PubSub的消息。gcpdataflow中的文档表明,当管道使用数据接收器终止时,数据包就完成了,在我的例子中,数据接收

我正在尝试使用同步拉API使用GooglePubSub消息。这在Apache Beam Google PubSub IO连接器库中提供。 我想用KafkaIO将已消费的消息写入Kafka。我想使用FlinkRunner来执行作业,因为我们在GCP之外运行这个应用程序

我面临的问题是,在GCP PubSub中,消费的消息没有得到确认。我已确认本地Kafka实例已使用来自GCP PubSub的消息。gcpdataflow中的文档表明,当管道使用数据接收器终止时,数据包就完成了,在我的例子中,数据接收器就是Kafka

但由于代码是在ApacheFlink中运行的,而不是在GCP数据流中运行的,因此我认为与确认提交的消息相关的某种回调不会被触发。
我做错了什么

                   pipeline
                    .apply("Read  GCP PubSub Messages", PubsubIO.readStrings()
                            .fromSubscription(subscription)
                    )
                    .apply(ParseJsons.of(User.class))
                    .setCoder(SerializableCoder.of(User.class))
                    .apply("Filter-1", ParDo.of(new FilterTextFn()))
                    .apply(AsJsons.of(User.class).withMapper(new ObjectMapper()))
                    .apply("Write to Local Kafka",
                            KafkaIO.<Void,String>write()
                                    .withBootstrapServers("127.0.0.1:9092,127.0.0.1:9093,127.0.0.1:9094")
                                    .withTopic("test-topic")
                                    .withValueSerializer((StringSerializer.class))
                                    .values()
                    );
管道
.apply(“读取GCP PubSub消息”,PubsubIO.readStrings()
.fromSubscription(订阅)
)
.apply(ParseJsons.of(User.class))
.setCoder(SerializableCoder.of(User.class))
.apply(“过滤器-1”,第页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页,共页)
.apply(AsJsons.of(User.class).withMapper(newObjectMapper()))
.apply(“写信给当地卡夫卡”,
卡夫卡约
.使用BootstrapServer(“127.0.0.1:9092127.0.0.1:9093127.0.0.1:9094”)
.withTopic(“测试主题”)
.withValueSerializer((StringSerializer.class))
.values()
);
在梁中提到:

检查点用于将接收到的消息确认回Pubsub(以便它们可以在Pubsub端失效),以及在需要恢复检查点时对已使用的消息进行NACK(以便Pubsub将立即重新发送这些消息)

ACK没有链接到数据流,您应该在数据流上具有相同的行为。ack在检查点上发送。通常,检查点是您在流上设置的窗口


但是,你们并没有设置窗户!默认情况下,windows是全局的,只有在结束时,如果您优雅地停止工作,它才会关闭(甚至,我对此也不确定)。无论如何,更好的解决方案是使用固定窗口(例如5分钟)来确认每个窗口上的消息。

我修复此解决方案的方法是使用Guillaume Blaquiere()建议查看检查点。即使在管道中添加Window.into()函数后,源PubSub订阅终结点也没有收到ACK。
问题出在Flink服务器配置中,我没有提到检查点配置。如果没有这些参数,将禁用检查点

state.backend: rocksdb
state.checkpoints.dir: file:///tmp/flink-1.9.3/state/checkpoints/
这些配置应该放在flink_home/conf/flink-conf.yaml中。
添加这些条目并重新启动flink后。在GCP pubsub监控图表中,所有积压(未确认的消息)都变为0。

您如何验证消息未被确认?在google pubsub控制台中,它显示该订阅的未确认消息图表。您是否以流模式处理消息?是。我们使用Google GCP pubsub Java客户端使用同步拉式API来消费数据,同步拉式API具有内置的轮询机制,以每请求1000条消息的批量消费数据,然后这些消息通过构建器管道顺序处理。如果差异批处理/拉式API中有明确的标志。。我不知道。谢谢你!!我将尝试此方法并更新此线程。我非常感谢你!这个解决方案对我不起作用。我确实将其添加到管道
.apply(“FixedWindowsLabel”,Window.into(FixedWindows.of(Duration.standardSeconds(5L)))
。。。但是没有帮助你是什么意思?管道工作,但消息不是ack,对吗?是的。管道工作,但没有ACK。请注意,当我使用DirectRunner(嵌入式默认运行程序)时,ACK可以工作。。不知何故,ACKs在FlinkRunnerIt的《奇怪》中不起作用,也许是个bug。您可以尝试在中打开一个问题