|
1 | | -"use strict"; |
| 1 | +import type { BrokerOptions, MetricRegistry, ServiceBroker } from "moleculer"; |
| 2 | +import { Errors } from "moleculer"; |
2 | 3 |
|
3 | 4 | {{#needChannels}} |
4 | | -const ChannelMiddleware = require("@moleculer/channels").Middleware; |
5 | | -{{#tracing}}const ChannelTracing = require("@moleculer/channels").Tracing;{{/tracing}} |
| 5 | +import { Middleware as ChannelMiddleware } from "@moleculer/channels"); |
| 6 | +{{#tracing}}import { Tracing as ChannelTracing } from "@moleculer/channels";{{/tracing}} |
6 | 7 | {{/needChannels}} |
7 | 8 |
|
8 | 9 | {{#needWorkflows}} |
9 | | -const WorkflowsMiddleware = require("@moleculer/workflows").Middleware; |
| 10 | +import { Middleware as WorkflowsMiddleware } = require("@moleculer/workflows"); |
10 | 11 | {{/needWorkflows}} |
11 | 12 |
|
12 | 13 | /** |
@@ -36,7 +37,7 @@ const WorkflowsMiddleware = require("@moleculer/workflows").Middleware; |
36 | 37 | * |
37 | 38 | * @type {import('moleculer').BrokerOptions} |
38 | 39 | */ |
39 | | -module.exports = { |
| 40 | +const brokerConfig: BrokerOptions = { |
40 | 41 | // Namespace of nodes to segment your nodes on the same network. |
41 | 42 | namespace: "", |
42 | 43 | // Unique node identifier. Must be unique in a namespace. |
@@ -96,7 +97,8 @@ module.exports = { |
96 | 97 | // Backoff factor for delay. 2 means exponential backoff. |
97 | 98 | factor: 2, |
98 | 99 | // A function to check failed requests. |
99 | | - check: err => err && !!err.retryable |
| 100 | + check: (err: Error) => |
| 101 | + err && err instanceof Errors.MoleculerRetryableError && !!err.retryable, |
100 | 102 | }, |
101 | 103 |
|
102 | 104 | // Limit of calling level. If it reaches the limit, broker will throw an MaxCallLevelError error. (Infinite loop protection) |
@@ -143,7 +145,7 @@ module.exports = { |
143 | 145 | // Number of milliseconds to switch from open to half-open state |
144 | 146 | halfOpenTime: 10 * 1000, |
145 | 147 | // A function to check failed requests. |
146 | | - check: err => err && err.code >= 500 |
| 148 | + check: (err: Error) => err && err instanceof Errors.MoleculerError && err.code >= 500, |
147 | 149 | }, |
148 | 150 |
|
149 | 151 | // Settings of bulkhead feature. More info: https://moleculer.services/docs/0.15/fault-tolerance.html#Bulkhead |
@@ -245,3 +247,5 @@ module.exports = { |
245 | 247 |
|
246 | 248 | } |
247 | 249 | }; |
| 250 | + |
| 251 | +export = brokerConfig; |
0 commit comments