Quick Start — Next.js
1. Install
Section titled “1. Install”npm install @queuebase/nextjs zod2. Define jobs
Section titled “2. Define jobs”Create a job router with Zod-validated inputs:
import { createJobRouter, job } from "@queuebase/nextjs";import { z } from "zod";
export const jobs = createJobRouter({ sendEmail: job({ input: z.object({ to: z.string().email(), subject: z.string(), body: z.string(), }), handler: async ({ input, jobId, attempt }) => { // your logic here return { sent: true }; }, defaults: { retries: 3, backoff: "exponential", }, }),});
export type JobRouter = typeof jobs;3. Create a client
Section titled “3. Create a client”The client gives you a type-safe way to enqueue jobs:
import { createClient } from "@queuebase/nextjs";import { jobs } from "./index";
export const jobClient = createClient(jobs, { apiUrl: process.env.QUEUEBASE_API_URL ?? "http://localhost:3847", apiKey: process.env.QUEUEBASE_API_KEY, callbackUrl: process.env.QUEUEBASE_CALLBACK_URL ?? "http://localhost:3000/api/queuebase",});4. Create the webhook handler
Section titled “4. Create the webhook handler”This is the endpoint Queuebase calls to execute your jobs:
import { createHandler } from "@queuebase/nextjs/handler";import { jobs } from "@/jobs";
export const POST = createHandler(jobs);5. Enqueue a job
Section titled “5. Enqueue a job”Call .enqueue() from a server action, route handler, or anywhere server-side:
import { jobClient } from "@/jobs/client";
const { jobId, getStatus } = await jobClient.sendEmail.enqueue({ to: "user@example.com", subject: "Welcome", body: "Hello!",});6. Run the dev server
Section titled “6. Run the dev server”npx queuebase devThis starts a local Queuebase server on port 3847 that stores jobs in SQLite and polls/executes them by calling back to your app.
Start your Next.js app in another terminal (npm run dev) and you’re ready to go.