NestJS
A custom NestJS transport wiring all five KubeMQ messaging patterns into the microservices ecosystem with idiomatic decorators, a CQRS bridge, and DI.
@kubemq/nestjs-transport is a
custom NestJS transport that integrates KubeMQ into the NestJS
microservices ecosystem. It surfaces all five KubeMQ messaging patterns — Commands, Queries,
Events, Events Store, and Queues — through idiomatic @*Handler decorators and a standard
ClientProxy, so a Nest app sends and handles KubeMQ messages with the same DI, modules, and
testing patterns it already uses for HTTP. It is built on the native
kubemq-js SDK and speaks gRPC directly to the broker
on port 50000.
Why KubeMQ + NestJS
- Idiomatic decorators —
@CommandHandler,@QueryHandler,@EventHandler,@EventStoreHandler, and@QueueHandlerreplace manual@MessagePattern/@EventPatternmetadata wiring; the right KubeMQ pattern is attached for you. - One transport, five patterns — a single
KubeMQServerstrategy (inbound) andKubeMQClientProxy(outbound) cover every pattern; theKubeMQRecordbuilder re-targets the message type with.asQuery(),.asEventStore(), or.asQueue(). - Dynamic-module DI —
forRoot/forRootAsync/register/registerAsync/forFeature/forTestregister the connection and named clients through NestJS dependency injection. - Distributed CQRS — the CQRS bridge routes
@nestjs/cqrsCommandBus,QueryBus, andEventBustraffic across services over KubeMQ channels. - TypeScript-first — full type safety with an ESM + CJS dual build and per-pattern context types.
- Broker-free tests —
MockKubeMQClient,MockKubeMQServer, andKubeMQModule.forTest()exercise services and handlers without a live broker.
Installation
npm install @kubemq/nestjs-transport kubemq-jsMost peer dependencies already ship with a typical NestJS project; install any that are missing:
npm install @nestjs/common @nestjs/core @nestjs/microservices rxjs reflect-metadataOptional peer dependencies enable specific features — @nestjs/terminus for the health-check
indicator and @nestjs/cqrs for the CQRS bridge:
npm install @nestjs/terminus # health checks
npm install @nestjs/cqrs # CQRS bridgePrerequisites: Node.js 20.11.0 or later and a running KubeMQ broker (default
localhost:50000). The transport is a native gRPC SDK client — there is no connector flag to
enable; the gRPC API on 50000 is always on. Start a local broker with Docker (gRPC on 50000,
the shared HTTP server and dashboard on 9090):
docker run -d \ --name kubemq \ -p 50000:50000 \ -p 9090:9090 \ -e KUBEMQ_TOKEN=YOUR_LICENSE_KEY \ europe-docker.pkg.dev/kubemq/images/kubemq:nextSupported versions
| Requirement | Supported versions |
|---|---|
| Language | TypeScript 5.5+ (ESM + CJS dual build) |
| Runtime | Node.js >= 20.11.0 |
| NestJS | 10.x or 11.x |
| KubeMQ SDK | kubemq-js ^3.0.1 |
| Package | @kubemq/nestjs-transport 1.0.0 |
Architecture
A KubeMQ-backed NestJS app is a
hybrid application: the HTTP app stays as-is
while the KubeMQ transport is attached as a microservice. Inbound handlers run through the
KubeMQServer strategy passed to app.connectMicroservice({ strategy }); outbound clients are
KubeMQClientProxy instances registered with KubeMQModule. Both wrap a kubemq-js client and
speak gRPC to the broker on port 50000.
Decorated handlers and injected client proxies both wrap kubemq-js and reach the broker over native gRPC.
Capabilities
The transport plugs into NestJS DI and dispatch. Each capability below documents the integration's own API surface and links to the underlying KubeMQ concept rather than re-teaching it.
| Capability | Surface | KubeMQ concept |
|---|---|---|
| Commands / Queries | @CommandHandler / @QueryHandler, client.send() | RPC |
| Events | @EventHandler, client.emit() | Events |
| Events Store | @EventStoreHandler, .asEventStore() | Events Store |
| Queues | @QueueHandler, .asQueue(), manual ack | Queues |
| Module DI | forRoot / register / forFeature / forTest | — |
| Distributed CQRS | KubeMQCqrsModule over @nestjs/cqrs buses | — |
Usage
The five handler decorators and the KubeMQRecord builder — send and handle every pattern.
Module configuration
forRoot / forRootAsync, register / registerAsync, forFeature, and multi-broker DI.
CQRS bridge
Route @nestjs/cqrs CommandBus, QueryBus, and EventBus over KubeMQ channels.
Next steps
Getting started
Stand up a hybrid app, register a handler, and send your first command in minutes.
Concepts
The transport model, send/emit mapping, contexts, serialization, and connection lifecycle.
Guides
Production hardening — TLS/auth, reconnection, DLQ, validation, idempotency, and testing.
Reference
Configuration options, the full decorator/context API, and the error catalog.
New to integrations? See what an integration is for
the mental model, or start with the KubeMQ Getting Started guide for core
broker concepts. This transport speaks native gRPC on port 50000 — it is a direct SDK client,
not a connector.
Was this page helpful?