【问题标题】:Flutter Cloud Pub Sub - How to create a StreamingPull that will continuously listen for messages?Flutter Cloud Pub Sub - 如何创建一个持续监听消息的 StreamingPull?
【发布时间】: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


【解决方案1】:

很遗憾,这是不可能的。

我决定更改实现而不使用 Pub-Sub。

谷歌开发者说

遗憾的是,您无法使用 REST API 执行“StreamingPull”——这就是它的本质。 ?

【讨论】:

    猜你喜欢
    • 2018-03-29
    • 2022-01-01
    • 1970-01-01
    • 2023-04-03
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    相关资源
    最近更新 更多