C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • Cluster Mode
  • Microservices
  • Observability
  • Security Layers
  • Universal Signals
  • Canx Flow
  • Maintenance
Enterprise

Microservices & Event Bus

Build scalable distributed systems with built-in Service Discovery and Event Bus. Supports Redis for production and in-memory for development.

Event Bus (Pub/Sub)

Asynchronous communication between services with Redis or in-memory support.

Service Discovery

Automatic service registration and discovery with health checks.

Load Balancing

Built-in round-robin and weighted load balancing across instances.

RPC Framework

Type-safe remote procedure calls with circuit breaker support.

Publishing Events

The Event Bus allows your services to communicate asynchronously without tight coupling. Use eventBus().publish() to emit events.

services/order.service.ts
1import { eventBus } from 'canxjs';
2
3// Publish an event
4await eventBus().publish('order.created', {
5 orderId: '123',
6 amount: 99.00,
7 customer: 'john@example.com'
8});
9
10// Publish with metadata
11await eventBus().publish('user.registered', {
12 userId: 'usr_456',
13 email: 'jane@example.com'
14}, {
15 priority: 'high',
16 retries: 3
17});

Subscribing to Events

Use the @Subscribe decorator or subscribe programmatically to handle events from other services.

services/email.service.ts
1import { Subscribe } from 'canxjs';
2
3class EmailService {
4 @Subscribe('order.created')
5 async onOrderCreated(payload: any) {
6 await sendOrderConfirmation(payload.orderId);
7 }
8
9 @Subscribe('user.registered')
10 async onUserRegistered(payload: any) {
11 await sendWelcomeEmail(payload.email);
12 }
13}
14
15// Or subscribe programmatically
16eventBus().subscribe('payment.failed', async (payload) => {
17 await notifyAdmin(payload);
18});

Service Registry

Automatic service discovery and load balancing. Services register themselves upon startup and can discover other services by name.

app.ts
1import { createServiceRegistry } from 'canxjs';
2
3const registry = createServiceRegistry({
4 driver: 'redis', // or 'consul', 'etcd'
5 ttl: 30000 // Health check interval
6});
7
8// Register this instance
9await registry.register('payment-service', '10.0.0.5', 3000);
10
11// Discover other services
12const userService = await registry.discover('user-service');
13// Result: { host: '10.0.0.2', port: 4000, healthy: true }
14
15// Load-balanced discovery (round-robin)
16const instance = await registry.discoverOne('api-gateway');

RPC Framework

Type-safe remote procedure calls with automatic service discovery and circuit breaker support.

clients/user.client.ts
1import { createRpcClient } from 'canxjs';
2
3// Create typed RPC client
4const userClient = createRpcClient<UserService>({
5 service: 'user-service',
6 timeout: 5000
7});
8
9// Call remote methods
10const user = await userClient.getUser('usr_123');
11const users = await userClient.listUsers({ page: 1, limit: 10 });
12
13// With circuit breaker
14const orderClient = createRpcClient<OrderService>({
15 service: 'order-service',
16 circuitBreaker: {
17 threshold: 5,
18 timeout: 30000
19 }
20});

Configuration

DriverUse CaseConfig
memoryDevelopment, testingNone required
redisProductionREDIS_URL
consulEnterpriseCONSUL_URL

Next Steps

Explore durable workflows and other enterprise features.