Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you do batch pull messages with Google Pub Sub?

Trying to optimize our application but doing batch pulling. Pub Sub seems to allow asynchronously pulling one message at a time with different client nodes, but is there no way for a single node to do a batch pull from pub sub?

Both Streaming Pull and Pull RPC both only allow the subscriber to consume one message at a time. Right now, it looks like we would have to pull one message at a time and do application level batching.

Any insight would be helpful. Pretty new to this GCP in general.

like image 635
TerraChu Avatar asked Oct 12 '25 10:10

TerraChu


1 Answers

The underlying pull and streaming pull operations can receive batches of messages in the same response. The Cloud Pub/Sub client library, which uses streaming pull, breaks these batches apart and hands them to the provided user callback one at a time. Therefore, you need not worry about optimizing the underlying receiving of messages.

If your concern is optimizing the subscriber code at the application level, e.g., you want to batch writes into a database, then you have a couple of options:

  1. Use Pull directly, which allows one to process all of the messages in a batch at a time. Note that using pull effectively requires many simultaneously outstanding pull requests and replacing requests that return with new requests immediately.

  2. In your user callback, re-batch messages and once the batch reaches a desired size (or you've waited a sufficient amount of time to fill the batch), process all of the messages together and then ack them.

like image 121
Kamal Aboul-Hosn Avatar answered Oct 15 '25 18:10

Kamal Aboul-Hosn