nestrs-microservices 0.3.6

Microservice transport and client primitives for nestrs.
Documentation

nestrs-microservices

Microservice transports and client proxy for nestrs: request/response and fire-and-forget patterns over optional backends (TCP, NATS, Redis, gRPC, Kafka, MQTT, RabbitMQ — feature-gated).

Also re-exports nestrs_events::EventBus and wires #[on_event] handlers registered via #[event_routes].

Docs: docs.rs/nestrs-microservices · Repo: github.com/Joshyahweh/nestrs

Install

[dependencies]
nestrs-microservices = { version = "0.3.6", features = ["nats"] }
# or: features = ["redis"], ["kafka"], ["mqtt"], ["rabbitmq"], ["grpc"], etc.

From the umbrella crate you can use:

nestrs = { version = "0.3.6", features = ["microservices", "microservices-nats"] }

Example: ClientProxy over a transport

use nestrs_microservices::{ClientProxy, NatsTransport, NatsTransportOptions};
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), nestrs_microservices::TransportError> {
    let transport = Arc::new(NatsTransport::new(NatsTransportOptions::new(
        "nats://127.0.0.1:4222",
    )));

    let proxy = ClientProxy::new(transport);

    #[derive(serde::Serialize)]
    struct Ping {
        msg: &'static str,
    }

    #[derive(serde::Deserialize)]
    struct Pong {
        echo: String,
    }

    let out: Pong = proxy
        .send("app.ping", &Ping { msg: "hi" })
        .await?;

    println!("{}", out.echo);
    Ok(())
}

Handlers are implemented on injectable types using #[micro_routes] + #[message_pattern] / #[event_pattern] (see main nestrs docs).

Per-handler cross-cutting (Nest-like, not identical): #[use_micro_interceptors(...)], #[use_micro_guards(...)], #[use_micro_pipes(...)] — types implement MicroIncomingInterceptor, MicroCanActivate, MicroPipeTransform (see crate docs).

Custom brokers: implement Transport and optionally consume the JSON protocol described in the wire and custom modules.

Wire format stability: golden JSON fixtures live in tests/fixtures/ and are checked by tests/wire_conformance.rs. The doc revision constant is WIRE_FORMAT_DOC_REVISION (bump when changing serde shapes).

gRPC: JSON payloads match wire inside protobuf fields; server dispatch uses the same wire::dispatch_send / dispatch_emit as other transports. Clients: GrpcTransportOptions::new(..).with_request_timeout(..).

RabbitMQ: one work queue (default nestrs.micro) carries wire::WireRequest JSON; request/reply uses a private reply queue name in reply. Bootstrap with NestFactory::create_microservice_rabbitmq when using the umbrella crate feature microservices-rabbitmq.

Features

Feature Purpose
nats NATS request/reply + events
redis Redis lists / pub-sub style bridge
grpc gRPC transport
kafka Kafka request topic consumer
mqtt MQTT RPC-style topics
rabbitmq AMQP 0-9-1 via lapin (work queue + reply queues)
microservice-metrics Handler metrics hooks

License

MIT OR Apache-2.0.