使用 Dataflow Java SDK 2 从 Pubsub 读取 [英] Reading from Pubsub using Dataflow Java SDK 2
问题描述
Google Cloud Platform for Java SDK 2.x 的许多文档都告诉您参考 Beam 文档.
A lot of the documentation for the Google Cloud Platform for Java SDK 2.x tell you to reference Beam documentation.
当使用 Dataflow 从 PubSub 读取时,我是否仍然应该执行 PubsubIO.Read.named("name").topic("");
When reading from PubSub using Dataflow, should I still be doing PubsubIO.Read.named("name").topic("");
或者我应该做其他事情吗?
Or should I be doing something else?
此外,有没有一种方法可以将 Dataflow 接收到的 PubSub 数据打印到标准输出或文件?
Also building off of that, is there a way to just print PubSub data received by the Dataflow to standard output or to a file?
推荐答案
对于 Apache Beam 2.2.0,您可以定义以下转换以从 Pub/Sub 订阅中拉取消息:
For Apache Beam 2.2.0, you can define the following transform to pull messages from a Pub/Sub subscription:
PubsubIO.readMessages().fromSubscription("subscription_name")
这是定义从 Pub/Sub 拉取消息的转换的一种方法.但是,PubsubIO
类包含用于拉取消息的不同方法.每种方法的功能略有不同.请参阅 PubsubIO 文档.
This is one way to define a transform that will pull messages from Pub/Sub. However, the PubsubIO
class contains different methods for pulling messages. Each method has slightly different functionality. See the PubsubIO documentation.
您可以使用 TextIO
类将 Pub/Sub 消息写入文件.请参阅 TextIO 文档.请参阅记录管道消息文档以将发布/订阅消息写入stdout代码>.
You can write the Pub/Sub messages to a file using the TextIO
class. See the examples in the TextIO documentation. See the Logging Pipeline Messages documentation for writing Pub/Sub messages to stdout
.
这篇关于使用 Dataflow Java SDK 2 从 Pubsub 读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!