Scale your application using CanxJS microservices. Support for multiple transport layers.
Support for TCP, Redis, NATS, MQTT, and Kafka.
Build scalable microservice architectures.
Easily communicate between services.
Run HTTP and Microservices in the same app.
1import { createApp, MicroserviceOptions, Transport } from "canxjs";23async function bootstrap() {4const app = createApp();56// Connect Microservice strategy7app.connectMicroservice<MicroserviceOptions>({8transport: Transport.TCP,9options: {10host: 'localhost',11port: 300112}13});1415await app.startAllMicroservices();16}
1import { Controller } from "canxjs";2import { MessageHandler, EventHandler } from "canxjs/microservices";34@Controller()5export class MathController {67// Request-Response pattern8@MessageHandler({ cmd: 'sum' })9accumulate(data: number[]): number {10return (data || []).reduce((a, b) => a + b);11}1213// Event pattern (Fire and forget)14@EventHandler('user_created')15handleUserCreated(data: Record<string, unknown>) {16console.log('User created event received', data);17}18}
1import { ClientProxy, ClientProxyFactory, Transport } from "canxjs/microservices";23export class UserService {4private client: ClientProxy;56constructor() {7this.client = ClientProxyFactory.create({8transport: Transport.TCP,9options: { port: 3001 }10});11}1213getSum(numbers: number[]) {14return this.client.send({ cmd: 'sum' }, numbers);15}16}