-
Can anyone help me out. I cannot see where I'm going wrong. I've got a very simple process which creates a subscriber to a topic where the messages are published with an ordering key. I want to receive a batch of the messages, process them and then call ack for the batch all in one go. Processing the messages in a batch will be more efficient but I'm finding that the receive call back is only called once and isn't called again until an ack is sent. More details of the code. The receive callback places the message and ackhandler onto a thread safe queue to be process by a separate thread. The separate thread is waiting on that queue and will take what ever messages our on that queue, process them and then call ack for all of them. When the messages have been placed on the topic with a single ordering key there will only ever be a single message received prior to the ack being call. If multiple ordering keys are used it will have multiple messages returned prior to ack being called. I've tried to set the I cannot find anything which suggests to me that this is intended behaviour but also I cannot see what I might be doing wrong either. I do seem to be using an old version of the api 1.24. incase it is old behaviour. If this should work can anyone point me to some example code which performs what I expect so I can see the difference with my own code please? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I think I've found the answer to my own question. Incase it is helpful for others in future. There is a single runnable_messages_ queue and multiple threads read from that single queue it has to wait until the HandleDone has happened before placing the next message on the runnable_messages_ queue as it cannot be certain what order those runnable_messages_ might end up being processed in by the multiple threads. From my perspective it would be nice to separate the action of ack/nack from completion of the receive call back so that the receiver can offload the work to be aggregated into a batch of work. For examine have a BatchAckHandler which allowed you to ack a message within a batch but it is not acked until some later point. Maybe there is a way and i've just not see it? |
Beta Was this translation helpful? Give feedback.
-
There is currently no API to process messages in batches, nor to ack them in batches. AFAIK, all Pub/Sub client libraries do the same thing, and the rationale includes:
I understand that there is an additional CPU cost involved in making more RPCs. Maybe we should consider batching the acks, on the other hand, this may be not trivial as the leases would need to be extended while the batch is being formed (maybe, leases are much longer, maybe a batch formed in a few milliseconds is enough). |
Beta Was this translation helpful? Give feedback.
There is currently no API to process messages in batches, nor to ack them in batches. AFAIK, all Pub/Sub client libraries do the same thing, and the rationale includes:
I understand that there is an additional CPU cost involved in making more RPCs. Maybe we should consi…