New release is coming soon! If you want to try out the latest features, simply run npm i -s moleculer@next. The docs for the latest version are available here.

Configuration

Broker options

These options can be used in ServiceBroker constructor or in moleculer.config.js file.

List of all available broker options:

  • namespace: String - Namespace of nodes to segment your nodes on the same network (e.g.: “development”, “staging”, “production”). Default: ""
  • nodeID: String - Unique node identifier. Must be unique in a namespace. If not the broker will throw a fatal error and stop the process. Default: hostname + PID
  • logger: Boolean | String | Object | Array<Object> ) - Logger class. By default, it prints message to the console. Read more. _Default: "Console"
  • logLevel: String | Object - Log level for loggers (trace, debug, info, warn, error, fatal). Read more. Default: info
  • transporter: String | Object | Transporter - Transporter configuration. Read more. Default: null
  • requestTimeout: Number - Number of milliseconds to wait before reject a request with a RequestTimeout error. Disabled: 0 Default: 0
  • retryPolicy: Object - Retry policy configuration. Read more.
  • contextParamsCloning: Boolean - Cloning the params of context if enabled. High performance impact. Use it with caution! Default: false
  • dependencyInterval: Configurable interval (defined in ms) that’s used by the services while waiting for dependency services. Default: 1000
  • maxCallLevel: Number - Limit of calling level. If it reaches the limit, broker will throw an MaxCallLevelError error. (Infinite loop protection) Default: 0
  • heartbeatInterval: Number - Number of seconds to send heartbeat packet to other nodes. Default: 5
  • heartbeatTimeout: Number - Number of seconds to wait before setting remote nodes to unavailable status in Registry. Default: 15
  • tracking: Object - Tracking requests and waiting for running requests before shutdowning. (Graceful shutdown) Read more.
  • disableBalancer: Boolean - Disable built-in request & emit balancer. Transporter must support it, as well. Read more. Default: false
  • registry: Object - Settings of Service Registry.
  • circuitBreaker: Object - Settings of Circuit Breaker.
  • bulkhead: Object - Settings of bulkhead.
  • transit.maxQueueSize: Number - A protection against inordinate memory usages when there are too many outgoing requests. If there are more than stated outgoing live requests, the new requests will be rejected with QueueIsFullError error. Default: 50000
  • transit.maxChunkSize Number - Maximum chunk size while streaming. Default: 256KB
  • transit.disableReconnect: Boolean - Disables the reconnection logic while starting a broker. Default: false
  • transit.disableVersionCheck: Boolean - Disable protocol version checking logic in Transit. Default: false
  • transit.packetLogFilter: Array - Filters out the packets in debug log messages. It can be useful to filter out the HEARTBEAT packets while debugging. Default: []
  • uidGenerator: Function - Custom UID generator function for Context ID.
  • errorHandler: Function - Global error handler function.
  • cacher: String | Object | Cacher - Cacher settings. Read more. Default: null
  • serializer: String | Serializer - Instance of serializer. Read more. Default: JSONSerializer
  • validator: Boolean | Validator - Enable the default or create custom parameters validation. Default: true
  • errorRegenerator: Regenerator - Instance of error regenerator. Read more. Default: null
  • metrics: Boolean | Object - Enable & configure metrics feature. Default: false
  • tracing: Boolean | Object - Enable & configure tracing feature. Default: false
  • internalServices: Boolean | Object - Register internal services at start. Default: true
  • internalServices.$node - Object - Extend internal services with custom actions. Default: null
  • internalMiddlewares: Boolean - Register internal middlewares. Default: true
  • hotReload: Boolean - Watch the loaded services and hot reload if they changed. Read more. Default: false
  • middlewares: Array<Object> - Register custom middlewares. Default: null
  • replDelimiter: String - Custom REPL commands delimiter. Default: mol $
  • replCommands: Array<Object> - Register custom REPL commands. Default: null
  • metadata: Object - Store custom values. Default: null
  • skipProcessEventRegistration: Boolean - Skip the default graceful shutdown event handlers. In this case, you have to register them manually. Default: false
  • maxSafeObjectSize: Number - Maximum size of objects that can be serialized. On serialization process, check each object property size (based on length or size property value) and trim it, if object size bigger than maxSafeObjectSize value. Default: null
  • created: Function - Fired when the broker created. Default: null
  • started: Function - Fired when the broker started (all local services loaded & transporter is connected). Default: null
  • stopped: Function - Fired when the broker stopped (all local services stopped & transporter is disconnected). Default: null
  • ServiceFactory: ServiceClass - Custom Service class. If not null, broker will use it when creating services by service schema. Default: null
  • ContextFactory: ContextClass - Custom Context class. If not null, broker will use it when creating contexts for requests & events. Default: null

Full options object

{
namespace: "dev",
nodeID: "node-25",

logger: true,
logLevel: "info",
logFormatter: "default",
logObjectPrinter: null,

transporter: "nats://localhost:4222",

requestTimeout: 5000,
retryPolicy: {
enabled: true,
retries: 5,
delay: 100,
maxDelay: 1000,
factor: 2,
check: err => err && !!err.retryable
},

contextParamsCloning: false,
maxCallLevel: 100,
heartbeatInterval: 5,
heartbeatTimeout: 15,

tracking: {
enabled: true,
shutdownTimeout: 5000,
},

disableBalancer: false,

registry: {
strategy: "RoundRobin",
preferLocal: true
},

circuitBreaker: {
enabled: true,
threshold: 0.5,
windowTime: 60,
minRequestCount: 20,
halfOpenTime: 10 * 1000,
check: err => err && err.code >= 500
},

bulkhead: {
enabled: true,
concurrency: 10,
maxQueueSize: 100,
},

transit: {
maxQueueSize: 50 * 1000,
disableReconnect: false,
disableVersionCheck: false,
packetLogFilter: ["HEARTBEAT"]
},

uidGenerator: null,

errorHandler: null,

cacher: "MemoryLRU",
serializer: "JSON",

validator: true,
errorRegenerator: null,

metrics: {
enabled: true,
reporter: [
"Console"
]
},

tracing: {
enabled: true,
exporter: [
"Console"
]
},

internalServices: true,
internalMiddlewares: true,

hotReload: true,

middlewares: ["MyMiddleware"],

replDelimiter: "mol $",
replCommands: [],

metadata: {
region: "eu-west1"
},

skipProcessEventRegistration: false,
maxSafeObjectSize: null,

ServiceFactory: null,
ContextFactory: null,

created(broker) {},

started(broker) {},

stopped(broker) {}
}