core package
Redis-backed message queue engine for the @imqueue framework — the transport shared by @imqueue/rpc and the job packages.
Start from IMQ.create(), which picks a queue adapter from the options and returns an unstarted IMessageQueue. The two concrete adapters are RedisQueue (a single Redis server) and ClusteredRedisQueue (several servers, with sends distributed between them), and either can also be constructed directly.
Remarks
Every queue follows the same lifecycle: construct, start(), then either consume message events or send(), and finally destroy() to release the connections. start() is required before publish() or subscribe(); send() starts the queue implicitly. stop() only stops consuming — it keeps the writer, the watcher lock and the maintenance timers alive, so destroy() is what actually releases resources.
Delivery is at-least-once, so message handlers must be idempotent. Within a single process, writer and watcher connections are shared per host:port and reference-counted, and exactly one queue per key prefix is elected as the watcher that releases delayed messages and performs maintenance.
Example
import IMQ, { IMQMode, type IMessageQueue } from '@imqueue/core';
const queue: IMessageQueue = IMQ.create('my-queue', {
host: 'localhost',
port: 6379,
});
queue.on('message', (message, id, from) => {
console.log(`got ${id} from ${from}`, message);
});
await queue.start();
await queue.send('my-queue', { hello: 'world' });
Classes
|
Class |
Description |
|---|---|
|
Scales a single logical queue horizontally across several redis instances. This is what IMQ.create() returns when IMQOptions.cluster or IMQOptions.clusterManagers is supplied. | |
|
Message queue factory. This is also the default export of | |
|
Redis-backed message queue with at-least-once delivery — the default IMessageQueue implementation, and what IMQ.create() returns for a single-server configuration. | |
|
Cluster manager that discovers redis cluster members from UDP broadcast announcements. Supply instances through IMQOptions.clusterManagers. |
Abstract Classes
|
Abstract Class |
Description |
|---|---|
|
Abstract base for cluster-membership discovery. A manager tracks the clusters it feeds and pushes server add/remove events into each of them, so several clustered queues can share one discovery mechanism. Supply instances through IMQOptions.clusterManagers. UDPClusterManager is the implementation shipped with the framework. |
Enumerations
|
Enumeration |
Description |
|---|---|
|
Operating mode of a queue instance, selecting which halves of the queue are active. Passed as the third constructor argument and defaults to IMQMode.BOTH. All modes still open a writer connection and take part in watcher election; the mode only controls whether a reader is created and whether sending is allowed. | |
|
Logger method to which profiling output is dispatched. Each value is the literal name of the corresponding ILogger method, so the level is used as a property lookup on the logger. |
Functions
|
Function |
Description |
|---|---|
|
Emits the profiling output for a single call: the elapsed time computed from | |
|
Wraps a class method so that its execution time and/or its call arguments are logged through the | |
|
Normalizes an arbitrary value into a LogLevel. |
Interfaces
|
Interface |
Description |
|---|---|
|
A server registered in a ClusteredRedisQueue: its address, plus the RedisQueue instance serving that host. Returned by ClusteredRedisQueue.addServer() so callers can address or inspect one specific host of the cluster. | |
|
Fully-resolved description of a single profiled call, as passed to logDebugInfo(). Normally constructed by the profile() decorator; supply it directly only to emit profiling output by hand. Every field except | |
|
Typed event map for a queue's | |
|
Membership callbacks a clustered queue hands to a ClusterManager so the manager can add and remove servers as it discovers them. Implement this to feed a clustered queue from your own discovery mechanism; ClusteredRedisQueue supplies an implementation of its own. | |
|
Minimal logging contract the framework writes diagnostics through. The global Pass an implementation as IMQOptions.logger to redirect queue output, or a no-op implementation to silence it. The method names match the members of LogLevel, so a level can be used as a property lookup on a logger. | |
|
Internal envelope of a queued message as it is stored in Redis: a generated id, the caller's payload, and the name of the queue that sent it. | |
|
Contract every messaging queue implementation fulfils. Implement it to add a transport of your own, or program against it to stay adapter-agnostic. A queue is an | |
|
Optional credentials for a queue host, forwarded to the Redis client as Supply both for a Redis ACL user, or just | |
|
A single queue-host endpoint: where to connect and, optionally, how to authenticate. | |
|
Options accepted by every queue implementation. Anything omitted falls back to DEFAULT_IMQ_OPTIONS — | |
|
A cluster that has been registered with a ClusterManager, carrying the generated id that identifies it for ClusterManager.remove(). | |
|
The ioredis | |
|
Address of a cluster server, as supplied to the cluster membership operations ICluster.add, ICluster.remove and ICluster.find. | |
|
Represents JSON-serializable array | |
|
Represents JSON serializable object | |
|
Options accepted by the profile() decorator. Every field is optional; omitted fields fall back to the IMQ_LOG_TIME, IMQ_LOG_ARGS and IMQ_LOG_LEVEL environment defaults. | |
|
Configuration for UDPClusterManager. Pass any subset to the constructor; unspecified values come from DEFAULT_UDP_CLUSTER_MANAGER_OPTIONS. |
Variables
|
Variable |
Description |
|---|---|
|
Default option values applied to every queue instance: | |
|
Default options applied to every UDPClusterManager unless overridden: broadcast address | |
|
Grace period (ms) for a graceful QUIT to complete before a channel is forcibly disconnected. A reader blocked on an infinite BRPOP/BLMOVE can never let QUIT through, so without this the socket would leak and keep the process alive. | |
|
Whether call-argument profiling is on by default, from the | |
|
Default logger method for profiling output, from the Accepts | |
|
Unit used when rendering profiled execution time, from the | |
|
Whether execution-time profiling is on by default, from the | |
|
Time in milliseconds allowed for releasing watcher locks when a shutdown signal is received, before the process is force-exited. Defaults to 1000; override with the |
Type Aliases
|
Type Alias |
Description |
|---|---|
|
Units in which profiled execution time can be rendered. | |
|
Any JSON value. | |
|
Constructor contract every queue adapter must satisfy: it takes the queue name, optional partial options and an optional IMQMode, and yields an IMessageQueue. IMQ.create() resolves an adapter of this shape from the registered vendor adapters and instantiates it. | |
|
The options actually handed to the UDP worker thread: everything except the logger, which is not structured-cloneable, and the signal-handling flag, which the main thread owns. |
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.