js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

Check Retryable/Non-Retryable Error for Subscribed Events and Action Accordingly

Open DeepanshuA opened this issue 3 years ago • 1 comments

Describe the proposal

When an app subscribes to messages/events, it needs to send back status as per https://docs.dapr.io/reference/api/pubsub_api/. Whether a message needs to be retried or dropped, should ideally depend on whether error encountered is retryable or not.

DeepanshuA avatar Aug 16 '22 14:08 DeepanshuA

The callback function looks like this currently:

const cb  = function (data: any) {
    // process the message
    // if error is thrown, message will be DROPPED
    // else message will be ACKED
 }

We need to change it to something similar to

const cb = function (data: any): PubSubCallbackResponse {
     const result = processMessage();
     if (isSuccess(result)) { return PubSubCallbackResponseMessage.Ack; }
     else if (needsRetry(result)) { return PubSubCallbackResponseMessage.Retry; }
     else { return PubSubCallbackResponseMessage.Drop; }
}

Note, this will be a breaking change in terms of the SDK contract, hence is being triaged to the next major release.

shubham1172 avatar Aug 16 '22 15:08 shubham1172