【发布时间】:2021-09-16 10:38:30
【问题描述】:
我有一个向订阅者发布消息的 API。
在 Flutter 中,我有一个订阅者,每次发布消息时我都需要从 API 中提取消息。
String subscriptionName = 'projects/test/subscriptions/test-sub';
pubSubClient.projects.subscriptions
.pull(
PullRequest.fromJson({
"maxMessages": 1000,
}),
subscriptionName)
.then((pullResponse) {
if (pullResponse.receivedMessages != null &&
pullResponse.receivedMessages.isNotEmpty) {
List<String> ids = [];
pullResponse.receivedMessages.forEach((element) {
ids.add(element.ackId);
});
pubSubClient.projects.subscriptions.acknowledge(
AcknowledgeRequest.fromJson({"ackIds": ids}), subscriptionName);
}
});
这可行,但只运行一次。在 Google Cloud API 中,它说使用 StreamingPull 来有效地接收消息?
如何在 Flutter 中做到这一点,还有哪些其他选择?
【问题讨论】:
-
您好,我也遇到了这个问题,请问您找到解决方案了吗?
-
很遗憾没有。我看到您也在 Github link 中发表了评论,我不得不更改实现。从 GitHub issue 中,开发人员表示无法完成,因为该包使用了 Pub Sub REST API。
标签: flutter google-cloud-pubsub