What is a callback?
A callback allows you to call a long running function without having to wait for its response. Instead of waiting for the request to finish, you can add a callback url to your published message and when the request finishes, we will call your callback URL with the response.
- You publish a message to QStash using the
/v2/publish
endpoint - QStash will enqueue the message and deliver it to the destination
- QStash waits for the response from the destination
- When the response is ready, QStash calls your callback URL with the response
How do I use Callbacks?
You can add a callback url in theUpstash-Callback
header when publishing a
message. The value must be a valid URL.
Max Message Size
in the
console.
Make sure you verify the authenticity of the callback request made to your API
by
verifying the signature.
What is a Failure-Callback?
Failure callbacks are similar to callbacks but they are called only when all the retries are exhausted and still the message can not be delivered to the given endpoint. This is designed to be an serverless alternative to List messages to DLQ. You can add a failure callback URL in theUpstash-Failure-Callback
header when publishing a
message. The value must be a valid URL.
Configuring Callbacks
Publishes/enqueues for callbacks can also be configured with the same HTTP headers that are used to configure direct publishes/enqueues. Instead of theUpstash
prefix for headers, the Upstash-Callback
/Upstash-Failure-Callback
prefix can be used to configure callbacks as follows: