Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@glidemq/hono

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glidemq/hono

Hono middleware for glide-mq - queue management REST API and SSE events

Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
18
20%
Maintainers
1
Weekly downloads
 
Created
Source

@glidemq/hono

npm CI license

Hono middleware for glide-mq - mount a full queue management REST API and real-time SSE event stream in one line.

Declare your queues in config, mount the middleware, and get 11 REST endpoints + live SSE - no boilerplate. Works with Hono's typed RPC client out of the box.

Part of the glide-mq ecosystem:

PackagePurpose
glide-mqCore queue library - producers, workers, schedulers, workflows
@glidemq/honoHono REST API + SSE middleware (you are here)
@glidemq/dashboardExpress web UI for monitoring and managing queues
@glidemq/nestjsNestJS module - decorators, DI, lifecycle management
examplesFramework integrations and use-case examples

Install

npm install @glidemq/hono glide-mq hono

Optional Zod validation:

npm install zod @hono/zod-validator

Quick Start

import { Hono } from 'hono';
import { glideMQ, glideMQApi } from '@glidemq/hono';

const app = new Hono();

app.use(glideMQ({
  connection: { addresses: [{ host: 'localhost', port: 6379 }] },
  queues: {
    emails: {
      processor: async (job) => {
        await sendEmail(job.data.to, job.data.subject);
        return { sent: true };
      },
      concurrency: 5,
    },
    reports: {},
  },
}));

app.route('/api/queues', glideMQApi());

export default app;

API

glideMQ(config)

Middleware factory. Creates a QueueRegistry and injects it into c.var.glideMQ.

interface GlideMQConfig {
  connection?: ConnectionOptions; // Required unless testing: true
  queues: Record<string, QueueConfig>;
  prefix?: string;                // Key prefix (default: 'glide')
  testing?: boolean;              // Use TestQueue/TestWorker (no Valkey)
}

interface QueueConfig {
  processor?: (job: Job) => Promise<any>; // Omit for producer-only
  concurrency?: number;                   // Default: 1
  workerOpts?: Record<string, unknown>;
}

glideMQApi(opts?)

Pre-built REST API sub-router. Mount it on any path.

interface GlideMQApiConfig {
  queues?: string[];    // Restrict to specific queues
}

REST Endpoints

MethodRouteDescription
POST/:name/jobsAdd a job
GET/:name/jobsList jobs (query: type, start, end)
GET/:name/jobs/:idGet a single job
GET/:name/countsGet job counts by state
POST/:name/pausePause queue
POST/:name/resumeResume queue
POST/:name/drainDrain waiting jobs
POST/:name/retryRetry failed jobs
DELETE/:name/cleanClean old jobs (query: grace, limit, type)
GET/:name/workersList active workers
GET/:name/eventsSSE event stream

Adding Jobs

curl -X POST http://localhost:3000/api/queues/emails/jobs \
  -H 'Content-Type: application/json' \
  -d '{"name": "welcome", "data": {"to": "user@example.com"}, "opts": {"priority": 10}}'

Retrying Failed Jobs

# Retry up to 50 failed jobs
curl -X POST http://localhost:3000/api/queues/emails/retry \
  -H 'Content-Type: application/json' \
  -d '{"count": 50}'

# Retry all failed jobs (omit body or send empty object)
curl -X POST http://localhost:3000/api/queues/emails/retry

Cleaning Old Jobs

# Remove completed jobs older than 1 hour, up to 200
curl -X DELETE 'http://localhost:3000/api/queues/emails/clean?grace=3600000&limit=200&type=completed'

# Remove all failed jobs (defaults: grace=0, limit=100, type=completed)
curl -X DELETE 'http://localhost:3000/api/queues/emails/clean?type=failed'

SSE Events

The events endpoint streams real-time updates. Available event types: completed, failed, progress, active, waiting, stalled, and heartbeat.

const eventSource = new EventSource('/api/queues/emails/events');

eventSource.addEventListener('completed', (e) => {
  console.log('Job completed:', JSON.parse(e.data));
});

eventSource.addEventListener('failed', (e) => {
  console.log('Job failed:', JSON.parse(e.data));
});

eventSource.addEventListener('progress', (e) => {
  console.log('Job progress:', JSON.parse(e.data));
});

Type-Safe RPC Client

import { hc } from 'hono/client';
import type { GlideMQApiType } from '@glidemq/hono';

const client = hc<GlideMQApiType>('http://localhost:3000/api/queues');

const res = await client.emails.jobs.$post({
  json: { name: 'welcome', data: { to: 'user@example.com' } },
});

Exported Types

import type {
  GlideMQConfig,       // Middleware configuration
  GlideMQEnv,          // Hono env type for c.var.glideMQ
  GlideMQApiConfig,    // API sub-router options
  QueueConfig,         // Per-queue config (processor, concurrency)
  QueueRegistry,       // Registry interface (for custom implementations)
  ManagedQueue,        // { queue, worker } pair returned by registry.get()
  JobResponse,         // Serialized job shape returned by API
  JobCountsResponse,   // { waiting, active, delayed, completed, failed }
  WorkerInfoResponse,  // Worker metadata
  GlideMQApiType,      // Hono RPC type for hc<GlideMQApiType>()
} from '@glidemq/hono';

Utilities

For advanced use cases (custom routes, custom API sub-routers):

import { serializeJob, serializeJobs, createEventsRoute } from '@glidemq/hono';

// serializeJob(job) - Convert a glide-mq Job to a plain JSON-safe object
// serializeJobs(jobs) - Serialize an array of jobs
// createEventsRoute() - SSE event handler factory for custom routers

Testing

No Valkey needed for unit tests:

import { createTestApp } from '@glidemq/hono/testing';

const { app, registry } = createTestApp({
  emails: {
    processor: async (job) => ({ sent: true }),
  },
});

const res = await app.request('/emails/jobs', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'test', data: {} }),
});

expect(res.status).toBe(201);

// Cleanup
await registry.closeAll();

Note: SSE in testing mode emits counts events (polling-based state diffs) rather than job lifecycle events (completed, failed, etc.).

Direct Registry Access

Access the registry in your own routes:

app.post('/send-email', async (c) => {
  const registry = c.var.glideMQ;
  const { queue } = registry.get('emails');

  const job = await queue.add('send', {
    to: 'user@example.com',
    subject: 'Hello',
  });

  return c.json({ jobId: job?.id });
});

Shutdown

For graceful shutdown, construct the registry yourself and pass it to glideMQ():

import { glideMQ, glideMQApi, QueueRegistryImpl } from '@glidemq/hono';

const registry = new QueueRegistryImpl({
  connection: { addresses: [{ host: 'localhost', port: 6379 }] },
  queues: { emails: { processor: processEmail } },
});

app.use(glideMQ(registry));
app.route('/api/queues', glideMQApi());

process.on('SIGTERM', async () => {
  await registry.closeAll();
  process.exit(0);
});

License

Apache-2.0

Keywords

hono

FAQs

Package last updated on 06 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts