Examples
Topics
Create a topic and add 2 endpoints
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const topics = client.topics();
await topics.addEndpoints({
name: "topic_name",
endpoints: [
{ url: "https://my-endpoint-1" },
{ url: "https://my-endpoint-2" },
],
});
Get topic by name
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const topics = client.topics();
const topic = await topics.get("topicName");
console.log(topic.name, topic.endpoints);
List topics
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const topics = client.topics();
const allTopics = await topics.list();
for (const topic of allTopics) {
console.log(topic.name, topic.endpoints);
}
Remove an endpoint from a topic
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const topics = client.topics();
await topics.removeEndpoints({
name: "topic_name",
endpoints: [{ url: "https://my-endpoint-1" }],
});
Delete a topic
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const topics = client.topics();
await topics.delete("topicName");