bởi Tobias W.

Moleculer is a fast, feature-rich microservices framework for Node.js with built-in service discovery, load balancing, fault tolerance, caching, tracing, and pluggable transports.
This block delivers the full Moleculer microservices framework source, enabling you to create, register, and call services inside a Node.js process with built-in caching, metrics, logging, tracing, and transport layers. The typical buyer is a backend engineer embedding a complete service-mesh runtime into an existing Node.js or TypeScript application without depending on the published npm artifact.
cachers/ - Memory, MemoryLRU, and Redis cacher implementations plus a resolver factoryloggers/ - Console, File, Bunyan, Winston, Pino, Datadog, Log4js, Debug logger adaptersmetrics/ - MetricRegistry, Counter/Gauge/Histogram/Info types, and reporter adapters (Prometheus, Datadog, StatsD, CSV, Event, Console)middlewares/ - Built-in middleware pipeline supportregistry/ - Service registry and dynamic discovery internalsserializers/ - JSON, JSONExt, MsgPack, CBOR, Notepack serializer adaptersstrategies/ - Load-balancing strategies (round-robin, random, cpu-usage, latency, sharding)tracing/ - Distributed tracing with Jaeger, Zipkin, Datadog, NewRelic, Event exporterstransporters/ - TCP, NATS, MQTT, Redis, Kafka, AMQP transport adaptersvalidators/ - Parameter validation layer (fastest-validator integration)service-broker.js - Central broker; creates and manages all servicesservice.js - Service class definitioncontext.js - Request/call context objecterrors.js - All framework error classestransit.js - Inter-node message transitpackets.js - Protocol packet definitionsmiddleware.js - Middleware runnerlogger-factory.js - Logger resolution and constructionconstants.js - Shared constantsutils.js - Internal utility helpershealth.js - Node health-check helperslock.js - Async lock primitiverunner.js / runner-esm.mjs - CLI runner entry pointsinternals.js - Internal service registrationsKhởi chạy sandbox cách ly và chạy phía máy chủ — không cần cài đặt cục bộ.
Tetrees AI Review cho phiên bản này
This Express backend / api completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Quy trình avcp-2026-08-04.1 · SHA-256 11f14aa2d6fd9469…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Đã đánh giá 4 thg 8, 2026
Đưa sản phẩm này thẳng vào AI IDE, trình tạo web hoặc cloud IDE của bạn.
Kết nối Tetrees với AI IDE tương thích để liệt kê sản phẩm bạn sở hữu và nhận ZIP đã xác minh mà không cấp quyền tải lên của người bán.
Chưa có đánh giá.
Sign in to join the discussion
Loading discussion…
async-storage.js - AsyncLocalStorage wrappercpu-usage.js - CPU usage samplernpm install args eventemitter2 fastest-validator glob ipaddr.js kleur lodash lru-cache recursive-watch
No native build steps, pod installs, or prebuild commands are required. All dependencies are pure JavaScript.
source/ directory into your project, for example at lib/moleculer/.tsconfig.json:{
"compilerOptions": {
"paths": {
"moleculer/*": ["lib/moleculer/*"]
}
}
}
import ServiceBroker = require("./lib/moleculer/service-broker");
REDIS_URL - used by Redis cacher/transporter if you pass it as a connection stringDATADOG_API_KEY - needed only if using Datadog logger or metrics reporterrunner-esm.mjs as the entry point.function resolve(
opt: Record<string, any> | string | boolean | null
): BaseCacher | null;
Resolves and instantiates a cacher from a string name ("Memory", "Redis", a redis:// URL), a config object { type, options }, or true for the default in-memory cacher. Returns null if opt is falsy. Use this when wiring broker options or writing middleware that needs caching without hardcoding a cacher class.
function resolve(
opt: Record<string, any> | string
): BaseLogger;
Resolves and instantiates a logger by string name ("Console", "Winston", etc.) or config object { type, options }. Throws BrokerOptionsError on unknown type. Use this to build a logger pipeline before constructing the broker, or to swap loggers in tests.
function resolve(
opt: Record<string, any> | string
): BaseReporter;
Resolves a metrics reporter by name ("Prometheus", "StatsD", "Console", etc.) or config object. Throws BrokerOptionsError on unknown type. Use this when configuring the MetricRegistry with a custom reporter list.
function register(name: string, value: any): void;
Adds a custom cacher or reporter class under a given name so it can later be resolved by that name string. Use this to extend the framework with third-party adapters without modifying source files.
Create a broker with the default Memory cacher, define a math service, and call an action.
const ServiceBroker = require("./lib/moleculer/service-broker");
const broker = new ServiceBroker({
logger: { type: "Console", options: { level: "info" } },
cacher: "Memory"
});
broker.createService({
name: "math",
actions: {
add(ctx: any) {
return Number(ctx.params.a) + Number(ctx.params.b);
}
}
});
broker.start()
.then(() => broker.call("math.add", { a: 5, b: 3 }))
.then((result: number) => console.log("Result:", result))
.then(() => broker.stop());
Resolve a Redis cacher from a connection string and pass it directly to the broker.
const ServiceBroker = require("./lib/moleculer/service-broker");
const { resolve: resolveCacher } = require("./lib/moleculer/cachers");
const cacher = resolveCacher("redis://localhost:6379");
const broker = new ServiceBroker({ cacher });
broker.createService({
name: "cache-demo",
actions: {
async get(ctx: any) {
const cached = await this.broker.cacher.get(ctx.params.key);
if (cached) return cached;
const value = { computed: true, key: ctx.params.key };
await this.broker.cacher.set(ctx.params.key, value, 60);
return value;
}
}
});
broker.start()
.then(() => broker.call("cache-demo.get", { key: "hello" }))
.then((v: any) => console.log(v))
.then(() => broker.stop());
Wire a Prometheus reporter into the broker so metrics are exposed at /metrics.
const ServiceBroker = require("./lib/moleculer/service-broker");
const { resolve: resolveReporter } = require("./lib/moleculer/metrics/reporters");
const reporter = resolveReporter({ type: "Prometheus", options: { port: 3030 } });
const broker = new ServiceBroker({
metrics: {
enabled: true,
reporter: [reporter]
}
});
broker.createService({ name: "ping", actions: { ping: () => "pong" } });
broker.start().then(() => {
console.log("Prometheus metrics available at http://localhost:3030/metrics");
});
const { register, resolve } = require("./lib/moleculer/loggers");
const BaseLogger = require("./lib/moleculer/loggers/base");
class MyLogger extends BaseLogger {
getLogHandler(bindings: any) {
return (type: string, args: any[]) => console.log(`[MY] [${type}]`, ...args);
}
}
register("MyLogger", MyLogger);
const logger = resolve({ type: "MyLogger", options: {} });
console.log(logger instanceof BaseLogger); // true
service-broker.js - Top-level broker class; all services, middleware, and subsystems attach here.service.js - Defines the Service class that broker.createService() instantiates.context.js - Encapsulates a single call/event invocation with params, metadata, and span.errors.js - Exports all named error classes (BrokerOptionsError, ServiceNotFoundError, etc.).transit.js - Handles serialization and dispatch of packets between nodes.packets.js - Packet schema definitions used by transit.middleware.js - Runs the ordered middleware chain for every broker operation.logger-factory.js - Constructs and binds logger instances to broker/service namespaces.constants.js - Shared string constants used across the framework.utils.js - isObject, isString, isInheritedClass, and other internal helpers.health.js - Gathers node health data for $node.health built-in action.lock.js - Lightweight async mutex used internally by cachers.runner.js / runner-esm.mjs - CLI entry points for moleculer-runner invocation.internals.js - Registers $node.* internal services on the broker.async-storage.js - AsyncLocalStorage wrapper for context propagation without explicit passing.cpu-usage.js - Periodic CPU sampling used by the cpu-usage load-balancing strategy.cachers/ - Base + Memory + MemoryLRU + Redis implementations with factory resolver.loggers/ - Base + eight concrete logger adapters with factory resolver.metrics/ - MetricRegistry, four metric types, seven reporter adapters, METRIC constants.middlewares/ - Built-in middleware hooks (circuit-breaker, bulkhead, retry, timeout, etc.).registry/ - Node/service/action/event catalog and endpoint lists.serializers/ - Pluggable serialization layer between transit peers.strategies/ - Endpoint selection strategies for load balancing.tracing/ - Distributed tracing context and exporter adapters.transporters/ - Network transport adapters for inter-node communication.validators/ - Parameter validation hook wrapping fastest-validator.lru-cache API mismatch - lru-cache v7+ changed its API; pin "lru-cache": "^6.0.0" in your package.json to match v0.15.0 expectations.ioredis is not in dependencies; install it separately with npm install ioredis before using the Redis cacher or transporter.require(); if your project is "type": "module", use createRequire or import via the .mjs runner; do not rename files.fastest-validator version - The validator adapter expects the v1.x API; npm install fastest-validator@^1 explicitly to avoid v2 breaking changes.nats, kafkajs, mqtt, amqplib); install only the ones you use..d.ts files use implicit any in several places; add "skipLibCheck": true in tsconfig.json to prevent type errors from source declarations.I have the Moleculer microservices framework source copied into `lib/moleculer/`
in my Node.js/TypeScript project. I also have the file `USAGE.md` in my project
root which documents the real exports, file layout, and working examples for this
source (upstream package: user@example.com).
Please help me integrate it step by step:
1. Read `USAGE.md` and `lib/moleculer/service-broker.js` to understand the broker API.
2. Create a `src/broker.ts` that instantiates a ServiceBroker with a Console logger
and Memory cacher, using only real exports shown in `USAGE.md`.
3. Create a sample service in `src/services/example.service.ts` with at least two actions.
4. Wire broker start/stop into my existing Express app lifecycle (show where to call
broker.start() relative to app.listen()).
5. Show how to add a Prometheus metrics reporter using `lib/moleculer/metrics/reporters`
resolve() function exactly as documented in `USAGE.md`.
6. Point out any missing peer dependencies I need to install based on the adapters I am using.
Do not invent any API methods. Use only symbols visible in `USAGE.md` and the source files.
Moleculer is released under the MIT License. See source/LICENSE if present, or refer to the official repository. Upstream package: moleculer on npm, maintained by MoleculerJS.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
Hướng dẫn cài đặt đầy đủ và prompt tích hợp sẽ mở khóa sau khi mua.
Automation, Utilities & Developer Tools
Miễn phí