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