Pulsar

Consumer

Configure job execution handlers via HTTP webhooks or direct JavaScript callbacks.

The consumer configuration determines how the Pulsar engine dispatches claimed jobs to your application logic.

Pulsar supports two distinct consumer execution patterns: HTTP Webhook Consumers (for decoupled, remote, or polyglot job dispatches) and Callback Consumers (for in-process, direct function execution).

Usage

Pass consumer inside the createQueue configuration object:

1. HTTP Consumer (type: "http")

Dispatches claimed jobs as HTTP POST requests to a specified endpoint.

export const Queue3 = createQueue({
  queue: "q_3",
  type: "STANDARD",
  consumer: { 
    type: "http", 
    url: "http://localhost:9999/test-f", 
    headers: { 
      "Authorization": `Bearer ${process.env.SUPABASE_ANON_KEY}`, 
    }, 
    timeoutMs: 5000, 
  }, 
  // ... other queue options
});

2. Callback Consumer (type: "callback")

Executes an in-process asynchronous function directly within the local JS runtime.

export const Queue3 = createQueue({
  queue: "q_3",
  type: "STANDARD",
  consumer: { 
    type: "callback", 
    handler: async (job) => { 
      console.log(`Processing job for queue ${job.queue}:`, job.payload); 
      // Process job logic here...
    }, 
  }, 
  // ... other queue options
});

Configuration Reference

HTTP Consumer Options

PropertyTypeRequiredDescription
type"http"YesSpecifies an HTTP webhook endpoint execution pattern.
urlstringYesThe destination endpoint URL where job payloads will be POSTed.
headersRecord<string, string>NoCustom HTTP request headers (e.g., authorization tokens, API keys).
timeoutMsnumberNoRequest timeout duration in milliseconds before marking the dispatch as failed.

Callback Consumer Options

PropertyTypeRequiredDescription
type"callback"YesSpecifies an in-process callback execution pattern.
handler(job: JobContext) => Promise<void>YesThe async handler function invoked when a worker claims a job batch.

The JobContext Structure

When using a callback consumer, your handler receives a JobContext object containing job details and operational metadata:

FieldTypeDescription
workerIdstringThe unique ID of the worker thread that claimed this batch. Essential for worker slot deregistration and lifecycle tracking.
queuestringThe ID/name of the queue from which the job was pulled.
payloadTThe primary data payload associated with the job.
attemptsnumberThe total number of execution attempts this job has undergone (for retry tracking).
timestampnumberUnix timestamp indicating when the job was dispatched or processed.

Callback Worker Deregistration Responsibility

When using type: "callback" for job dispatching, capturing the workerId alongside the job context arguments is mandatory.

Worker deregistration must be explicitly handled by your application-layer code once processing completes. The Pulsar engine is not responsible for automatically deregistering workers in callback mode.

Critical Engine Freeze Warning: If worker deregistration is omitted or ignored in your callback handler, the Pulsar engine will assume those worker slots remain perpetually occupied. Active concurrency slots will stay locked, causing queue execution to stall or pause completely until those workers are manually deregistered by the application layer.

On this page