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?