Publish to a topic with a 3 second delay and headers/body
You can make a topic on the QStash console or using the topics API
Copy
Ask AI
import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });const res = await client.publishJSON({ topic: "mytopic", body: { hello: "world" }, headers: { "test-header": "test-value" }, delay: 3,});// When publishing to a topic, the response is an array of messages for each URL in the topicconsole.log(res[0].messageId);
Callbacks are useful for long running functions. Here, QStash will return the response
of the publish request to the callback URL.We also change the method to GET in this use case so QStash will make a GET request to the url. The default
is POST.
Copy
Ask AI
import { Client } from "@upstash/qstash";const client = new Client({ token: "<QSTASH_TOKEN>" });const res = await client.publishJSON({ url: "https://my-api...", body: { hello: "world" }, callback: "https://my-callback...", failureCallback: "https://my-failure-callback...", method: "GET",});