Flutter Cloud Pub Sub - 如何创建将持续侦听消息的 StreamingPull?

Flutter Cloud Pub Sub - How to create a StreamingPull that will continuously listen for messages?

我有一个 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 中完成此操作以及还有哪些其他选项?

很遗憾,这是不可能的。

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

Google 开发者说

Sadly, you are NOT able to do a "StreamingPull" with the REST API – which is what this is.