@orion-js/echoes 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/request/index.js
CHANGED
|
@@ -19,6 +19,8 @@ async function request(options) {
|
|
|
19
19
|
const requestMaker = config_1.default?.requests?.makeRequest || makeRequest_1.makeRequest;
|
|
20
20
|
const requestOptions = {
|
|
21
21
|
url: (0, getURL_1.default)(service),
|
|
22
|
+
retries: options.retries,
|
|
23
|
+
timeout: options.timeout,
|
|
22
24
|
data: {
|
|
23
25
|
body,
|
|
24
26
|
signature
|
|
@@ -5,15 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeRequest = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const helpers_1 = require("@orion-js/helpers");
|
|
8
9
|
const makeRequest = async (options) => {
|
|
9
|
-
const result = await (0,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const result = await (0, helpers_1.executeWithRetries)(async () => {
|
|
11
|
+
return await (0, axios_1.default)({
|
|
12
|
+
method: 'post',
|
|
13
|
+
url: options.url,
|
|
14
|
+
timeout: options.timeout,
|
|
15
|
+
headers: {
|
|
16
|
+
'User-Agent': 'Orionjs-Echoes/1.1'
|
|
17
|
+
},
|
|
18
|
+
data: options.data
|
|
19
|
+
});
|
|
20
|
+
}, options.retries, 200);
|
|
17
21
|
return {
|
|
18
22
|
data: result.data,
|
|
19
23
|
statusCode: result.status
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { EchoesOptions } from '../types';
|
|
2
|
-
export default function (options: EchoesOptions): void
|
|
2
|
+
export default function startService(options: EchoesOptions): Promise<void>;
|
|
@@ -8,7 +8,7 @@ const config_1 = __importDefault(require("../config"));
|
|
|
8
8
|
const requestsHandler_1 = __importDefault(require("../requestsHandler"));
|
|
9
9
|
const types_1 = __importDefault(require("../echo/types"));
|
|
10
10
|
const http_1 = require("@orion-js/http");
|
|
11
|
-
function
|
|
11
|
+
async function startService(options) {
|
|
12
12
|
config_1.default.echoes = options.echoes;
|
|
13
13
|
if (options.requests) {
|
|
14
14
|
config_1.default.requests = options.requests;
|
|
@@ -18,13 +18,16 @@ function default_1(options) {
|
|
|
18
18
|
const kafka = new kafkajs_1.Kafka(options.client);
|
|
19
19
|
config_1.default.producer = kafka.producer(options.producer);
|
|
20
20
|
config_1.default.consumer = kafka.consumer(options.consumer);
|
|
21
|
-
config_1.default.producer.connect();
|
|
22
|
-
config_1.default.consumer.connect();
|
|
21
|
+
await config_1.default.producer.connect();
|
|
22
|
+
await config_1.default.consumer.connect();
|
|
23
23
|
for (const topic in options.echoes) {
|
|
24
24
|
const echo = options.echoes[topic];
|
|
25
25
|
if (echo.type !== types_1.default.event)
|
|
26
26
|
continue;
|
|
27
|
-
config_1.default.consumer.subscribe({
|
|
27
|
+
await config_1.default.consumer.subscribe({
|
|
28
|
+
topic,
|
|
29
|
+
fromBeginning: options.readTopicsFromBeginning === false ? false : true
|
|
30
|
+
});
|
|
28
31
|
}
|
|
29
32
|
config_1.default.consumer.run({
|
|
30
33
|
eachMessage: async (payload) => {
|
|
@@ -38,4 +41,4 @@ function default_1(options) {
|
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
|
-
exports.default =
|
|
44
|
+
exports.default = startService;
|
package/lib/types.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface RequestOptions<TParams> {
|
|
|
17
17
|
method: string;
|
|
18
18
|
service: string;
|
|
19
19
|
params: TParams;
|
|
20
|
+
retries?: number;
|
|
21
|
+
timeout?: number;
|
|
20
22
|
}
|
|
21
23
|
export interface RequestHandlerResponse {
|
|
22
24
|
result?: any;
|
|
@@ -24,6 +26,8 @@ export interface RequestHandlerResponse {
|
|
|
24
26
|
}
|
|
25
27
|
export interface MakeRequestParams {
|
|
26
28
|
url: string;
|
|
29
|
+
retries?: number;
|
|
30
|
+
timeout?: number;
|
|
27
31
|
data: {
|
|
28
32
|
body: object;
|
|
29
33
|
signature: string;
|
|
@@ -64,6 +68,10 @@ export interface EchoesOptions {
|
|
|
64
68
|
consumer?: ConsumerConfig;
|
|
65
69
|
requests?: RequestsConfig;
|
|
66
70
|
echoes: EchoesMap;
|
|
71
|
+
/**
|
|
72
|
+
* Defaults to true. When true, allows a reconnecting service to read missed messages.
|
|
73
|
+
*/
|
|
74
|
+
readTopicsFromBeginning?: boolean;
|
|
67
75
|
}
|
|
68
76
|
export interface EchoesConfigHandler {
|
|
69
77
|
producer?: Producer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/echoes",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@orion-js/env": "^3.5.0",
|
|
21
|
-
"@orion-js/helpers": "^3.5.
|
|
22
|
-
"@orion-js/http": "^3.
|
|
23
|
-
"@orion-js/services": "^3.5.
|
|
21
|
+
"@orion-js/helpers": "^3.5.3",
|
|
22
|
+
"@orion-js/http": "^3.6.0",
|
|
23
|
+
"@orion-js/services": "^3.5.3",
|
|
24
24
|
"axios": "^0.24.0",
|
|
25
25
|
"jssha": "^3.2.0",
|
|
26
26
|
"kafkajs": "^1.15.0",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "420961a09399dd52f21c3e5ec756fb3e5bda0dc3"
|
|
44
44
|
}
|