I was reading the documentation from Google about pull vs streaming pull but could not quite get it. Can someone explain to me the difference and also would be helpful if someone has implemented it and could point me to the resources. Many thanks.
1 Answers
When using Cloud Pub/Sub pull, one sends a PullRequest and receives a single PullResponse that contains up to the number of messages specified in the request (or an error if there was an issue in getting messages). Each request has a single corresponding response. With streaming pull, one sends a StreamingPullRequest, which opens a stream along which data will be received. While the stream is open, Cloud Pub/Sub will send a StreamingPullResponse with more messages whenever the messages are available for delivery. The single request can result in many responses.
In general, for highest throughput and lowest latency, streaming pull is the right choice. Streaming pull keeps a connection open to Cloud Pub/Sub and therefore messages can be sent to that connection as soon as they are available. Achieving these properties with just using pull can be difficult. Without the stream, messages can only be delivered when an explicit request comes in. These messages may have been ready for delivery for some time. In order to achieve high throughput and low latency with pull, one has to have many simultaneous outstanding requests where new requests are created as soon as old requests receive a response. Using pull can make sense when the subscriber needs much more control over when messages arrive and latency/throughput are not a concern.
The Cloud Pub/Sub client libraries are built on top of streaming pull and so if you can use one of those, you can avoid needing to implement streaming pull calls directly. All of the client libraries are open source and so if you want to see examples of making the streaming pull calls directly you can look in the code. For example, Java has the StreamingSubscriberConnection.