简体   繁体   English

使用 Apache Beam 从 PubSubIO 获取 Pub/Sub 消息的 messageId 字段

[英]Get Pub/Sub message's messageId field from PubSubIO with Apache Beam

Is it possible the get somehow the messageId field of a Pub/Sub message in a DoFn after using the PubSubIO Beam source to read the messages?在使用 PubSubIO Beam 源读取消息后,是否有可能以某种方式获取 DoFn 中 Pub/Sub 消息的 messageId 字段?

I need the default id which was assigned by the Pub/Sub service.我需要由 Pub/Sub 服务分配的默认 ID。 I want to log it for debugging purposes.我想记录它以进行调试。

Using a custom attribute for the unique id and the withIdAttribute() method is not possible for me, because I have no influence on the publisher in this case.对唯一 id 和 withIdAttribute() 方法使用自定义属性对我来说是不可能的,因为在这种情况下我对发布者没有影响。

I use the 2.2.0 version of the Dataflow Java SDK.我使用 2.2.0 版本的 Dataflow Java SDK。

Support for reading the Pubsub message id was added starting with Beam v2.16.0.从 Beam v2.16.0 开始,添加了读取 Pubsub 消息 ID 的支持。 To turn it on, replace .readMessages() with .readMessagesWithMessageId() in your pipeline setup then it is as easy as message.getMessageId() after that change.要打开它,请在您的管道设置.readMessagesWithMessageId()替换为.readMessages() ,然后在更改后就和message.getMessageId()一样简单。

For debugging purposes you can use the seek option .出于调试目的,您可以使用seek 选项

It creates a snapshot of the messages which you can replay when needed.它会创建您可以在需要时重播的消息快照。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM