Pubsub 消息缺少时间戳属性
Pubsub message is missing a timestamp attribute
我正在尝试从 Apache Beam 读取 Pubsub 消息的时间戳值。
p.apply("Read PubSub messages", PubsubIO.readMessagesWithAttributes()
.withIdAttribute("msg_id")
.withTimestampAttribute("timestamp")
.fromSubscription(options.getPubsubSubscription()))
但不幸的是,我收到了以下错误,这让我非常惊讶,因为我认为每条消息都有默认时间戳。
An exception occured while executing the Java class.
PubSub message is missing a value for timestamp attribute timestamp
为什么我的消息没有时间戳?是因为我通过 Pubsub UI 发布了吗?
如果您省略 .withTimestampAttribute()
,每条 Pub/Sub 条消息都将分配默认时间戳。添加 .withTimestampAttribute("timestamp")
意味着您将在每条消息的 timestamp
属性中提供时间戳。例如,使用 UI:
然后,窗口将与这些时间戳相关,如果您需要从管道内访问它,您可以使用 ProcessContext.timestamp()
(more details )。
我正在尝试从 Apache Beam 读取 Pubsub 消息的时间戳值。
p.apply("Read PubSub messages", PubsubIO.readMessagesWithAttributes()
.withIdAttribute("msg_id")
.withTimestampAttribute("timestamp")
.fromSubscription(options.getPubsubSubscription()))
但不幸的是,我收到了以下错误,这让我非常惊讶,因为我认为每条消息都有默认时间戳。
An exception occured while executing the Java class.
PubSub message is missing a value for timestamp attribute timestamp
为什么我的消息没有时间戳?是因为我通过 Pubsub UI 发布了吗?
如果您省略 .withTimestampAttribute()
,每条 Pub/Sub 条消息都将分配默认时间戳。添加 .withTimestampAttribute("timestamp")
意味着您将在每条消息的 timestamp
属性中提供时间戳。例如,使用 UI:
然后,窗口将与这些时间戳相关,如果您需要从管道内访问它,您可以使用 ProcessContext.timestamp()
(more details