Configs2026年5月16日·1 分钟阅读

Moleculer — Progressive Microservices Framework for Node.js

Build scalable microservices with built-in service discovery, load balancing, and fault tolerance. Moleculer provides a convention-driven framework for Node.js that handles inter-service communication, caching, and event-driven architecture out of the box.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Moleculer Overview
通用 CLI 安装命令
npx tokrepo install bacb199a-5143-11f1-9bc6-00163e2b0d79

Introduction

Moleculer is a progressive microservices framework for Node.js that provides everything needed to build distributed systems without external infrastructure dependencies. It includes built-in service discovery, request-response and event-driven communication, load balancing, circuit breakers, and caching in a batteries-included package.

What Moleculer Does

  • Provides service discovery and inter-service communication without external service mesh
  • Handles load balancing across service instances with multiple strategies (round-robin, random, CPU-based)
  • Includes built-in circuit breaker, retry, timeout, and bulkhead patterns for fault tolerance
  • Supports multiple transport protocols (NATS, Redis, AMQP, MQTT, TCP) for service messaging
  • Offers request-level caching, parameter validation, and metrics collection out of the box

Architecture Overview

Moleculer organizes applications into services, each containing actions (request-response handlers), events (pub/sub handlers), and lifecycle hooks. A ServiceBroker instance on each node manages local services and handles communication with remote nodes via a configurable transporter. Nodes discover each other through the transporter layer and exchange heartbeats to maintain a distributed service registry. When a node calls a remote action, the broker serializes the request, routes it through the transporter to an available instance, and deserializes the response, all transparently to the calling code.

Self-Hosting & Configuration

  • Initialize projects with the CLI wizard or manually by creating a moleculer.config.js file
  • Configure the transporter (NATS, Redis, TCP, etc.) for inter-node communication
  • Define services as classes or objects with actions, events, and lifecycle methods
  • Deploy multiple instances of services across nodes for horizontal scaling
  • Use the built-in API Gateway service to expose actions as REST or GraphQL endpoints

Key Features

  • Zero-config service discovery and automatic load balancing between instances
  • Pluggable architecture with swappable transporters, serializers, cachers, and validators
  • Built-in API Gateway for exposing services via REST, WebSocket, or GraphQL
  • Distributed event bus with balanced and broadcast event delivery modes
  • Middleware system for request/response pipeline customization (logging, auth, tracing)

Comparison with Similar Tools

  • NestJS — opinionated Node.js framework with microservice support; Moleculer focuses exclusively on microservices with deeper built-in distributed systems patterns
  • Seneca — lightweight microservices toolkit; Moleculer provides more built-in features (caching, metrics, circuit breakers) without additional plugins
  • Dapr — language-agnostic sidecar runtime; Moleculer is Node.js-native with tighter integration and no sidecar overhead
  • gRPC — efficient RPC protocol; Moleculer provides a higher-level framework around service communication with built-in resilience patterns
  • Express + custom microservices — manual setup of discovery, balancing, and resilience; Moleculer handles all of these declaratively

FAQ

Q: Can Moleculer services communicate across different programming languages? A: Moleculer is primarily a Node.js framework, but it communicates via standard message brokers (NATS, Redis, AMQP). Non-Node.js services can participate by implementing the Moleculer protocol on a supported transporter.

Q: How does Moleculer handle service versioning? A: Services can be versioned by setting a version property. Multiple versions can run simultaneously and clients specify which version to call, enabling gradual migrations.

Q: What happens when a service instance crashes? A: The circuit breaker detects failures and stops routing to unhealthy instances. The service registry removes nodes that miss heartbeats. Remaining healthy instances continue serving requests.

Q: Can I run all services in a single process during development? A: Yes. Moleculer supports running multiple services in one broker instance for development, then distributing them across nodes in production without code changes.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产