Memory Queue

Process queue jobs in-memory for local development and testing.

Memory Queue processes jobs in the same Node.js process without an external queue backend. The memory provider requires no cloud accounts, SDKs, or infrastructure. ViteHub stores jobs in an in-memory array and processes them automatically when enqueued.

Before you start

Install @vitehub/queue. The memory provider has no additional dependencies.

Terminal
pnpm add https://pkg.pr.new/nuxt-hub/agent/@vitehub/queue@main

Configure Memory

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vitehub/queue/nuxt'],
  queue: {
    provider: 'memory',
  },
})
When no cloud environment is detected, ViteHub auto-selects the memory provider at runtime. You can omit the provider field entirely in development.

Define a queue

server/queues/welcome-email.ts
import { defineQueue } from '@vitehub/queue'

export default defineQueue(async (job) => {
  console.log('Processing:', job.payload)
  return { processed: true }
})

How auto-processing works

When runQueue() enqueues a message with the memory provider, ViteHub automatically fires the queue handler in a microtask. The handler runs asynchronously after the current request completes, so runQueue() returns immediately without waiting for the handler to finish.

server/api/send.post.ts
import { runQueue } from '@vitehub/queue'

export default defineEventHandler(async () => {
  // Returns immediately — handler runs in the background
  return runQueue('welcome-email', {
    id: `email-${Date.now()}`,
    payload: { to: 'user@example.com' },
  })
})

Errors from the handler are caught and logged to the console. Errors do not propagate to the caller or trigger retries.

Provider-specific methods

The memory provider exposes additional methods through getQueue() for inspecting and manually draining the message store.

server/api/queue/debug.get.ts
import { getQueue } from '@vitehub/queue'

export default defineEventHandler(async () => {
  const queue = await getQueue('welcome-email')

  return {
    size: queue.memory.size(),
    next: queue.memory.peek(3),
  }
})
MethodDescription
size()Returns the number of messages in the store.
peek(limit?)Returns up to limit messages without removing them.
drain(handler)Shifts messages off the store one by one, calling handler for each. Returns the count of messages processed.

What changes on Memory

ConcernBehavior
StorageIn-process array. Messages are lost when the server restarts.
ProcessingAutomatic via microtask after runQueue(). No separate worker needed.
RetriesNone. Failed jobs log an error and are not retried.
Message IDsGenerated as mem_<uuid> with a timestamp fallback.
The memory provider is not suitable for production. Messages do not survive restarts and there is no delivery guarantee. Use it for local development and testing, then switch to a hosted provider before deploying.