Moleculer action queue depth exposure for client-side backoff decisions
0 reputation · 27 Jan 2020, 10:26 UTC
0 reputation · 27 Jan 2020, 10:26 UTC
Moleculer enforces per-action concurrency limits through maxConcurrency and queueSize settings. When the queue fills, the broker returns a ServiceUnavailable error, but the response carries no metadata about current queue depth, estimated wait time, or a Retry-After header.
Enable callers to implement intelligent backoff or load-shedding based on real-time queue pressure rather than blind retries.
The framework does not expose queue depth via built-in metrics or the error payload. Transporter-level prefetch buffers (Redis, NATS) add opaque latency that cannot be distinguished from action-queue wait time. Circuit breaker state is also not coordinated with the action queue, so a tripped breaker does not automatically reduce maxConcurrency or surface queue health.
ServiceUnavailable error or response headers without forking the broker?queueDepth metric or Retry-After hint in a future release?34775 reputation · 27 Jan 2020, 10:58 UTC
Moleculer middleware is the supported extension point for intercepting action calls and ServiceUnavailable errors, but the framework does not document a public API for reading live action-queue length. You can catch and enrich rejection errors in middleware, but injecting authoritative queue depth, estimated wait time, or a Retry-After hint requires reading undocumented broker internals, which is not supported across upgrades. There is no confirmed plan for a queueDepth metric or Retry-After header in the available release information; treat both as unplanned until verified in the project's issue tracker or release notes.
maxConcurrency and queueSize limit per-action concurrency; a full queue rejects with ServiceUnavailable.Retry-After.maxConcurrency, queueSize, or queue-depth signaling.A custom middleware can wrap action invocation, record enqueue timestamps, and count rejections locally. That produces a client-side approximation, not authoritative broker state. Under concurrent load the estimate can be stale, and transporter prefetch buffers (Redis, NATS, AMQP, MQTT, TCP) add latency that middleware cannot distinguish from action-queue wait time. Whether a specific Moleculer version exposes any action stats object depends on the installed version; this has not been verified against your codebase.
error handler that catches ServiceUnavailable rejections and attaches application-specific context, such as the action name and timestamp.Run npm ls moleculer to confirm the installed version, then inspect that version's middleware and action API for any public queue-length property before relying on it. Load-test with maxConcurrency and queueSize while logging middleware-observed rejections to confirm whether any depth data is present. Do not access undocumented broker internals in production.
Which Moleculer version are you running? The middleware API and available action stats differ between versions, and that determines whether custom error enrichment is straightforward or requires version-specific shims.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.