This override is used by OpenNext to trigger the revalidation of stale routes.
When a stale route is served, OpenNext calls the send method of the queue override to revalidate the route:
- When the route is rendered by the Next server,
sendis called once the response is sent (inwaitUntilwhen the wrapper provides one). - With cache interception,
sendis awaited before the stale response is returned. If it throws, the error is logged and the request falls back to the Next server.
If you want to better understand how to implement your own Queue, the easiest way would be to take a look at the existing included Queue (opens in a new tab).
Couple of things to note :
- The default implementation use an SQS queue. This has the main advantage of being able to control the concurrency of the revalidations as well as avoiding trigerring the revalidation multiple times for the same route.
- The promise returned by
sendshould resolve once the message is accepted (or handed towaitUntil), not once the route is revalidated, so that the response is not delayed. - You don't have to use a queue at all. You could trigger the revalidation directly in the Queue override itself. You can see a very simple implementation of this in the
directoverride (opens in a new tab).
Included Queue
sqs
The SQS Queue will send a message to an SQS queue for each route that needs to be revalidated. It is used by default if you don't provide any Queue in your configuration.
It uses the @aws-sdk/client-sqs to interact with SQS.
Since @opennextjs/aws 4.1.6, the message is sent in the background when the wrapper provides a waitUntil (i.e. aws-lambda-streaming or aws-apigw-streaming) so that it does not delay the response. Otherwise, the response is sent once the message has been sent. The same applies to sqs-lite.
Requirements
- You need to provide the
REVALIDATION_QUEUE_URLenvironment variable to your server.
sqs-lite
The SQSLite Queue will send a message to an SQS queue for each route that needs to be revalidated.
This implementation is a lighter version of the sqs Queue as it uses aws4fetch to interact with SQS.
Requirements
- You need to provide the
REVALIDATION_QUEUE_URL,REVALIDATION_QUEUE_REGION(will fallback tous-east-1),AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEYandAWS_SESSION_TOKENenvironment variables to your server.
direct
The Direct Queue will directly trigger the revalidation of the route in the Queue override itself. It is useful for development purposes and when you don't want to use a queue.
Be careful with this implementation as it could lead to multiple revalidations of the same route. As send
resolves once the route is revalidated, it also delays the stale response when cache interception is
enabled.
dummy
The Dummy Queue is a dummy implementation that will throw an exception. It should not be used unless you want to disable ISR.