NextMQ

Configuration

configureNextMQ connects the SDK to your project using the keys from your dashboard. Call it once per server runtime, before any producer or worker is used.

lib/nextmq.ts
import { configureNextMQ } from '@nextmq/sdk'

configureNextMQ({
  serverUrl:      process.env.NEXTMQ_SERVER_URL!,
  apiKey:         process.env.NEXTMQ_API_KEY!,
  adminKey:       process.env.NEXTMQ_ADMIN_API_KEY,
  webhookSecret:  process.env.NEXTMQ_WEBHOOK_SECRET!,
  webhookBaseUrl: process.env.NEXTMQ_WEBHOOK_BASE_URL!,
})

Options#

OptionRequiredDescription
serverUrlYesYour project's NextMQ API endpoint, from the dashboard.
apiKeyYesThe app credential — enqueue jobs, register workers, and processor-side callbacks (progress, logs, data updates).
adminKeyNoThe admin credential for control-plane actions (pause, retry, remove jobs). Falls back to apiKey if omitted.
webhookSecretYesSigns and verifies the calls NextMQ makes to your webhook route. Copy it from the dashboard.
webhookBaseUrlYesYour app's public URL — where NextMQ calls back to run your jobs.
Note
Two scopes. apiKey grants the app scope; adminKey grants admin, a strict superset. If you only configure apiKey, the SDK uses it for everything — fine for getting started, but use a separate admin key in production.

Advanced options#

OptionDefaultDescription
requestTimeoutMsPer-request timeout for SDK calls to NextMQ.
webhookBasePath/api/nextmqPath your webhook route is mounted at. Must match where the route file lives.
webhookBodyLimitBytes1 MiBMax accepted webhook payload size before the route responds 413.
tenantIdExplicit project id, only needed if a key maps to more than one.

Where to call it#

Configuration is process-global and must run on every server entry point that touches the queue — your webhook route, your producer routes, and server actions. The simplest pattern is a tiny module that calls configureNextMQ, imported first by each of those files.

// At the top of any file that produces jobs or hosts the worker route:
import '@/lib/nextmq'
Tip
Env auto-config. If you skip configureNextMQ, the SDK reads its config from environment variables on first use — at minimum NEXTMQ_SERVER_URL and NEXTMQ_API_KEY. Calling it explicitly is recommended so config errors surface at startup instead of on the first queue call.

The webhook base URL#

NextMQ has to reach your app at a URL that doesn't change between deploys. Point webhookBaseUrl at a stable domain — your production or custom domain, never a unique per-deployment URL. On Vercel preview deployments, worker registration is blocked until you set it explicitly.

Heads up
See Deploying to Vercel for the exact environment setup and how to keep idle queues registered.