【发布时间】:2023-03-29 11:59:01
【问题描述】:
我正在使用 JAVA 客户端库从 AppEngine 灵活环境发布 Pubsub 消息,如下所示:
Publisher publisher = Publisher
.newBuilder(ProjectTopicName.of(Utils.getApplicationId(), "test-topic"))
.setBatchingSettings(
BatchingSettings.newBuilder()
.setIsEnabled(false)
.build())
.build();
publisher.publish(PubsubMessage.newBuilder()
.setData(ByteString.copyFromUtf8(message))
.putAttributes("timestamp", String.valueOf(System.currentTimeMillis()))
.build());
我正在订阅 Dataflow 中的主题并记录消息从 AppEngine flexible 到达 Dataflow 需要多长时间
pipeline
.apply(PubsubIO.readMessagesWithAttributes().fromSubscription(Utils.buildPubsubSubscription(Constants.PROJECT_NAME, "test-topic")))
.apply(ParDo.of(new DoFn<PubsubMessage, PubsubMessage>() {
@ProcessElement
public void processElement(ProcessContext c) {
long timestamp = System.currentTimeMillis() - Long.parseLong(c.element().getAttribute("timestamp"));
System.out.println("Time: " + timestamp);
}
}));
pipeline.run();
当我以每秒几条消息的速度发布消息时,日志显示消息到达 Dataflow 所需的时间在 100 毫秒到 1.5 秒之间。 但是当速率约为每秒 100 条消息时,时间总是在 100 毫秒 - 200 毫秒之间,这似乎完全足够了。 有人可以解释这种行为。似乎关闭发布者批处理不起作用。
【问题讨论】:
标签: java google-cloud-platform google-cloud-pubsub dataflow