@yolo-croket-dev/core 1.5.1 → 1.5.2
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.
|
@@ -26,13 +26,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.AmqpManagement = void 0;
|
|
27
27
|
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
28
28
|
const _1 = require(".");
|
|
29
|
-
const { SERVER_NAME } = process.env;
|
|
30
29
|
const msaLogger = new msa_logger_1.default(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
31
30
|
class AmqpManagement {
|
|
32
31
|
constructor(client) {
|
|
33
32
|
this.client = client;
|
|
34
33
|
}
|
|
35
|
-
paramProcessor(
|
|
34
|
+
paramProcessor(argParam, options) {
|
|
36
35
|
const param = { ...argParam };
|
|
37
36
|
if (!options) {
|
|
38
37
|
return param;
|
|
@@ -43,19 +42,13 @@ class AmqpManagement {
|
|
|
43
42
|
if (options.isCreateTraceId) {
|
|
44
43
|
param.traceId = (0, _1.generateTraceId)();
|
|
45
44
|
}
|
|
46
|
-
/** from 처리 */
|
|
47
|
-
param.from = `${SERVER_NAME}: ${messagePattern}`;
|
|
48
45
|
return param;
|
|
49
46
|
}
|
|
50
47
|
async call(funcName, messagePattern, payload, argParam, options) {
|
|
51
|
-
const param = this.paramProcessor({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
messagePattern,
|
|
57
|
-
options,
|
|
58
|
-
});
|
|
48
|
+
const param = this.paramProcessor(argParam || {
|
|
49
|
+
traceId: (0, _1.generateTraceId)(),
|
|
50
|
+
isInternal: true,
|
|
51
|
+
}, options);
|
|
59
52
|
try {
|
|
60
53
|
const result = await (0, _1.AmqpHandler)(this.client, messagePattern, {
|
|
61
54
|
payload,
|
|
@@ -72,14 +65,10 @@ class AmqpManagement {
|
|
|
72
65
|
return undefined;
|
|
73
66
|
}
|
|
74
67
|
onlyPublish(funcName, messagePattern, payload, argParam, options) {
|
|
75
|
-
const param = this.paramProcessor({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
options,
|
|
81
|
-
messagePattern,
|
|
82
|
-
});
|
|
68
|
+
const param = this.paramProcessor(argParam || {
|
|
69
|
+
traceId: (0, _1.generateTraceId)(),
|
|
70
|
+
isInternal: true,
|
|
71
|
+
}, options);
|
|
83
72
|
this.client.emit(messagePattern, {
|
|
84
73
|
payload,
|
|
85
74
|
param,
|
|
@@ -5,7 +5,6 @@ const common_1 = require("@nestjs/common");
|
|
|
5
5
|
const rxjs_1 = require("rxjs");
|
|
6
6
|
const msa_logger_1 = require("@yolo-croket-dev/msa-logger");
|
|
7
7
|
const _1 = require(".");
|
|
8
|
-
const { SERVER_NAME } = process.env;
|
|
9
8
|
const msaLogger = new msa_logger_1.MsaLogger(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
10
9
|
class HttpExceptionCustom extends common_1.HttpException {
|
|
11
10
|
constructor(response, status, subMessage, errInfo) {
|
|
@@ -17,13 +16,8 @@ class HttpExceptionCustom extends common_1.HttpException {
|
|
|
17
16
|
exports.HttpExceptionCustom = HttpExceptionCustom;
|
|
18
17
|
// eslint-disable-next-line max-len
|
|
19
18
|
async function AmqpHandler(client, messagePattern, payload) {
|
|
20
|
-
var _a, _b, _c
|
|
19
|
+
var _a, _b, _c;
|
|
21
20
|
let data;
|
|
22
|
-
/** from 처리 */
|
|
23
|
-
if (!((_a = payload.param) === null || _a === void 0 ? void 0 : _a.from)) {
|
|
24
|
-
// eslint-disable-next-line no-param-reassign
|
|
25
|
-
payload.param.from = `${SERVER_NAME}: ${messagePattern}`;
|
|
26
|
-
}
|
|
27
21
|
try {
|
|
28
22
|
data = await (0, rxjs_1.lastValueFrom)(client.send(messagePattern, payload).pipe());
|
|
29
23
|
if (data.isError) {
|
|
@@ -33,7 +27,7 @@ async function AmqpHandler(client, messagePattern, payload) {
|
|
|
33
27
|
* 파일 객체 처리
|
|
34
28
|
* 다른 서비스에서 이미 처리가 될 수 있음
|
|
35
29
|
* */
|
|
36
|
-
(0, _1.reWriteFileValue)((
|
|
30
|
+
(0, _1.reWriteFileValue)((_a = data === null || data === void 0 ? void 0 : data.arg) === null || _a === void 0 ? void 0 : _a.file);
|
|
37
31
|
const errInfo = data.errInfo ? data.errInfo : {
|
|
38
32
|
message: data.errMessage,
|
|
39
33
|
type: data.errType,
|
|
@@ -51,14 +45,14 @@ async function AmqpHandler(client, messagePattern, payload) {
|
|
|
51
45
|
}
|
|
52
46
|
catch (err) {
|
|
53
47
|
if (typeof err === 'string' && err.includes('There is no matching message handler defined in the remote service.')) {
|
|
54
|
-
msaLogger.error('NOT_EXISTS_MESSAGE_PATTERN', { traceId: ((
|
|
48
|
+
msaLogger.error('NOT_EXISTS_MESSAGE_PATTERN', { traceId: ((_b = payload === null || payload === void 0 ? void 0 : payload.param) === null || _b === void 0 ? void 0 : _b.traceId) || '-' }, { err });
|
|
55
49
|
throw new HttpExceptionCustom('해당 메시지 패턴은 존재하지 않습니다.', 404, 'There is no matching message handler defined in the remote service.', {
|
|
56
50
|
type: 'NOT_EXISTS_MESSAGE_PATTERN',
|
|
57
51
|
message: '해당 메시지 패턴은 존재하지 않습니다.',
|
|
58
52
|
});
|
|
59
53
|
}
|
|
60
54
|
else {
|
|
61
|
-
msaLogger.error('AMQP_HANDLER_ERROR', { traceId: ((
|
|
55
|
+
msaLogger.error('AMQP_HANDLER_ERROR', { traceId: ((_c = payload === null || payload === void 0 ? void 0 : payload.param) === null || _c === void 0 ? void 0 : _c.traceId) || '-' }, { err });
|
|
62
56
|
throw err;
|
|
63
57
|
}
|
|
64
58
|
}
|
|
@@ -35,6 +35,7 @@ exports.LoggingServiceInterceptor = void 0;
|
|
|
35
35
|
const common_1 = require("@nestjs/common");
|
|
36
36
|
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
37
37
|
const operators_1 = require("rxjs/operators");
|
|
38
|
+
const { SERVER_NAME } = process.env;
|
|
38
39
|
const msaLogger = new msa_logger_1.default(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
39
40
|
const MAX_CUT_LENGTH = 500;
|
|
40
41
|
let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
@@ -69,17 +70,23 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
69
70
|
return data;
|
|
70
71
|
}
|
|
71
72
|
intercept(context, next) {
|
|
72
|
-
var _a;
|
|
73
73
|
const now = Date.now();
|
|
74
74
|
// const args = context.getArgs();
|
|
75
75
|
const rmqContext = context.switchToRpc().getContext();
|
|
76
|
+
const data = context.switchToRpc().getData();
|
|
77
|
+
const from = data.param.from || '-';
|
|
78
|
+
const froms = data.param.froms || [from];
|
|
76
79
|
const originalMessage = rmqContext.getMessage();
|
|
77
80
|
const ctx = context.switchToHttp();
|
|
78
81
|
const request = ctx.getRequest();
|
|
79
82
|
const originalcontent = originalMessage.content;
|
|
80
83
|
const content = JSON.parse(originalcontent.toString());
|
|
81
84
|
const traceId = content.data.param ? content.data.param.traceId : '-';
|
|
82
|
-
|
|
85
|
+
/** from 변경 */
|
|
86
|
+
const tmpFrom = `${SERVER_NAME}: ${content.pattern}`;
|
|
87
|
+
data.param.from = tmpFrom;
|
|
88
|
+
froms.push(tmpFrom);
|
|
89
|
+
data.param.froms = froms;
|
|
83
90
|
msaLogger.printInputInterceptorService({
|
|
84
91
|
traceId,
|
|
85
92
|
messageBrokerInfo: {
|
|
@@ -87,7 +94,10 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
87
94
|
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
88
95
|
},
|
|
89
96
|
paramInfo: request.param,
|
|
90
|
-
traceInfo: {
|
|
97
|
+
traceInfo: {
|
|
98
|
+
from,
|
|
99
|
+
froms,
|
|
100
|
+
},
|
|
91
101
|
});
|
|
92
102
|
return next.handle()
|
|
93
103
|
.pipe((0, operators_1.tap)(() => {
|
|
@@ -102,7 +112,10 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
102
112
|
messagePatten: content.pattern,
|
|
103
113
|
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
104
114
|
},
|
|
105
|
-
traceInfo: {
|
|
115
|
+
traceInfo: {
|
|
116
|
+
from,
|
|
117
|
+
froms,
|
|
118
|
+
},
|
|
106
119
|
});
|
|
107
120
|
})).pipe((0, operators_1.catchError)((error) => {
|
|
108
121
|
msaLogger.printExceptionFliterService({
|
|
@@ -117,7 +130,10 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
117
130
|
messagePatten: content.pattern,
|
|
118
131
|
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
119
132
|
},
|
|
120
|
-
traceInfo: {
|
|
133
|
+
traceInfo: {
|
|
134
|
+
from,
|
|
135
|
+
froms,
|
|
136
|
+
},
|
|
121
137
|
});
|
|
122
138
|
const elapsed = Date.now() - now;
|
|
123
139
|
msaLogger.printOutService({
|
|
@@ -130,7 +146,10 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
130
146
|
messagePatten: content.pattern,
|
|
131
147
|
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
132
148
|
},
|
|
133
|
-
traceInfo: {
|
|
149
|
+
traceInfo: {
|
|
150
|
+
from,
|
|
151
|
+
froms,
|
|
152
|
+
},
|
|
134
153
|
});
|
|
135
154
|
throw error;
|
|
136
155
|
}));
|
package/interfaces/http.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolo-croket-dev/core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"author": "Yolo Co., Ltd.",
|
|
5
5
|
"description": "Yolo commonization module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@nestjs/common": "^8.2.3",
|
|
18
18
|
"@nestjs/microservices": "9.0.8",
|
|
19
19
|
"@yolo-croket-dev/logger": "^1.0.15",
|
|
20
|
-
"@yolo-croket-dev/msa-logger": "^
|
|
20
|
+
"@yolo-croket-dev/msa-logger": "^3.0.1",
|
|
21
21
|
"@yolo-croket-dev/redis": "^1.0.23",
|
|
22
22
|
"@yolo-croket-dev/swagger": "^0.0.7",
|
|
23
23
|
"axios": "^1.1.3",
|