我想根据字段的内容将 PCollection 的不同元素动态路由到不同的 PubSub 主题。主题不是持久的,但假设在运行时执行 PubSubIO.Write() 时它们存在。因此,Dataflow 应该只在运行时基于每条消息推断它们的名称。
BigQuery 和动态表名称存在该功能:https://beam.apache.org/documentation/sdks/javadoc/2.0.0/org/apache/beam/sdk/io/gcp/bigquery/DynamicDestinations.html
有没有办法用 PubSubIO 做类似的事情?
也许不是基于消息内容而是基于属性? https://beam.apache.org/documentation/sdks/javadoc/0.6.0/org/apache/beam/sdk/io/PubsubIO.PubsubMessage.html#getAttribute-java.lang.String-
最佳答案
Is there a way to do something similar with PubSubIO ?
Pub/Sub 没有等同于 DynamicDestinations
的东西。
您需要提前了解所有 Pub/Sub 主题,并在管道中定义它们。管道可以根据 Pub/Sub 消息的某些值或属性进行分区,并路由到适当的 Pub/Sub 主题。 Partition
转换将检查 PubsubMessage
并确定消息属于哪个分区。
引用:Partition
Maybe not based on the message content but on an attribute ?
是的,您可以访问消息的属性。
关于java - 根据消息内容从 Dataflow 作业写入动态 PubSub 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49109779/