Skip to content

[PubSub Api] How to create a StreamingPull that will continuously listen for messages? #262

@orgesballa

Description

@orgesballa

I have an API that publishes messages to subscribers.

In flutter, I have a subscriber and I need to pull messages from the API every time they are published.

 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);
      }
    });
This works but this is run only once. In the Google Cloud API, it says to use a StreamingPull to efficiently receive messages? 

How can this be done in flutter and what other options are there? 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions