mercredi 13 janvier 2021

Delayed Acknowledging GCloud Pub/Sub message

I am trying to implement a PubSub client that acts like AWS or Azure queues, however, I am facing problems with gcloud cpp sdk.

First of all, the provided example does not work out of the box - I had to put a sleep before session.cancel(), otherwise the message was not acknowledged. Is there a solid way to wait until the ack() operation is finished and check its status?

Besides, the c++ api seems to provide only an asynchronous method that does not fit to my usecase.

I need to implement the following interface that is plugged into a larger system via dependency injection. The system works in production on other clouds so I cannot change the architecture. Just need to implement the interface.

template<typename TItem, typename TReceipt>
class Queue{
public:
    /*!
    * Dequeues message from the queue and sets item and receipt 
    * Returns true on success
    */
    virtual bool Dequeue( TItem & item, TReceipt & receipt) = 0;

    /*!
    * Discards the item with `receipt` from the cloud queue.
    */
    virtual void Discard(const TReceipt & receipt) = 0;
};

AWS and Azure SDKs provide a receipt for each dequeued message so that I can discard it later, but I cannot figure out how to do that with pub/sub.

An obviously wrong solution would be to keep the session open and in the lambda wait for another condition_variable until the next time the Dequeue method is called. However, this looks like a quick and dirty solution. What is the proper way to implement this functionality with Pub/Sub?

Aucun commentaire:

Enregistrer un commentaire