@yolo-croket-dev/core 1.4.53 → 1.5.1-jun.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.
|
@@ -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,18 +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', {
|
|
49
|
-
traceId: ((_b = payload === null || payload === void 0 ? void 0 : payload.param) === null || _b === void 0 ? void 0 : _b.traceId) || '-'
|
|
50
|
-
}, { err });
|
|
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 });
|
|
51
55
|
throw new HttpExceptionCustom('해당 메시지 패턴은 존재하지 않습니다.', 404, 'There is no matching message handler defined in the remote service.', {
|
|
52
56
|
type: 'NOT_EXISTS_MESSAGE_PATTERN',
|
|
53
|
-
message: '해당 메시지 패턴은 존재하지 않습니다.'
|
|
57
|
+
message: '해당 메시지 패턴은 존재하지 않습니다.',
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
60
|
else {
|
|
57
|
-
msaLogger.error('AMQP_HANDLER_ERROR', {
|
|
58
|
-
traceId: ((_c = payload === null || payload === void 0 ? void 0 : payload.param) === null || _c === void 0 ? void 0 : _c.traceId) || '-'
|
|
59
|
-
}, { err });
|
|
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 });
|
|
60
62
|
throw err;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
@@ -30,6 +30,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.LoggingServiceInterceptor = void 0;
|
|
33
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
33
34
|
/* eslint-disable no-param-reassign */
|
|
34
35
|
const common_1 = require("@nestjs/common");
|
|
35
36
|
const msa_logger_1 = __importStar(require("@yolo-croket-dev/msa-logger"));
|
|
@@ -68,15 +69,17 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
68
69
|
return data;
|
|
69
70
|
}
|
|
70
71
|
intercept(context, next) {
|
|
72
|
+
var _a;
|
|
71
73
|
const now = Date.now();
|
|
72
|
-
const args = context.getArgs();
|
|
73
|
-
const
|
|
74
|
+
// const args = context.getArgs();
|
|
75
|
+
const rmqContext = context.switchToRpc().getContext();
|
|
76
|
+
const originalMessage = rmqContext.getMessage();
|
|
74
77
|
const ctx = context.switchToHttp();
|
|
75
78
|
const request = ctx.getRequest();
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const content = JSON.parse(message.content.toString());
|
|
79
|
+
const originalcontent = originalMessage.content;
|
|
80
|
+
const content = JSON.parse(originalcontent.toString());
|
|
79
81
|
const traceId = content.data.param ? content.data.param.traceId : '-';
|
|
82
|
+
const from = ((_a = content.data.param) === null || _a === void 0 ? void 0 : _a.from) || '-';
|
|
80
83
|
msaLogger.printInputInterceptorService({
|
|
81
84
|
traceId,
|
|
82
85
|
messageBrokerInfo: {
|
|
@@ -84,9 +87,13 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
84
87
|
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
85
88
|
},
|
|
86
89
|
paramInfo: request.param,
|
|
90
|
+
traceInfo: { from },
|
|
87
91
|
});
|
|
88
92
|
return next.handle()
|
|
89
|
-
.pipe((0, operators_1.
|
|
93
|
+
.pipe((0, operators_1.map)(data => {
|
|
94
|
+
console.log('@data', data);
|
|
95
|
+
}), (0, operators_1.tap)(() => {
|
|
96
|
+
console.log('@top');
|
|
90
97
|
const elapsed = Date.now() - now;
|
|
91
98
|
msaLogger.printOutService({
|
|
92
99
|
traceId,
|
|
@@ -94,6 +101,11 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
94
101
|
status: 200,
|
|
95
102
|
ms: elapsed,
|
|
96
103
|
},
|
|
104
|
+
messageBrokerInfo: {
|
|
105
|
+
messagePatten: content.pattern,
|
|
106
|
+
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
107
|
+
},
|
|
108
|
+
traceInfo: { from },
|
|
97
109
|
});
|
|
98
110
|
})).pipe((0, operators_1.catchError)((error) => {
|
|
99
111
|
msaLogger.printExceptionFliterService({
|
|
@@ -104,6 +116,11 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
104
116
|
message: error.subMessage,
|
|
105
117
|
stack: error.stack,
|
|
106
118
|
},
|
|
119
|
+
messageBrokerInfo: {
|
|
120
|
+
messagePatten: content.pattern,
|
|
121
|
+
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
122
|
+
},
|
|
123
|
+
traceInfo: { from },
|
|
107
124
|
});
|
|
108
125
|
const elapsed = Date.now() - now;
|
|
109
126
|
msaLogger.printOutService({
|
|
@@ -112,6 +129,11 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
112
129
|
status: error.status,
|
|
113
130
|
ms: elapsed,
|
|
114
131
|
},
|
|
132
|
+
messageBrokerInfo: {
|
|
133
|
+
messagePatten: content.pattern,
|
|
134
|
+
payload: JSON.stringify(this.keyCutter(JSON.stringify(request.payload))),
|
|
135
|
+
},
|
|
136
|
+
traceInfo: { from },
|
|
115
137
|
});
|
|
116
138
|
throw error;
|
|
117
139
|
}));
|
|
@@ -33,6 +33,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.RPCInterceptor = void 0;
|
|
36
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
36
37
|
/* eslint-disable no-param-reassign */
|
|
37
38
|
const common_1 = require("@nestjs/common");
|
|
38
39
|
const core_1 = require("@nestjs/core");
|
|
@@ -205,8 +206,10 @@ let RPCInterceptor = class RPCInterceptor {
|
|
|
205
206
|
errMessage,
|
|
206
207
|
errAction,
|
|
207
208
|
};
|
|
208
|
-
|
|
209
|
-
|
|
209
|
+
if (!Number.isNaN(staticRetryCount)
|
|
210
|
+
&& staticRetryCount
|
|
211
|
+
&& err.isRetry !== false) {
|
|
212
|
+
/** 재시도 로직이 필요한 경우, 0보다 커야 정의된것. 기본값이 0, isRetry값이 false로 정의된 에러가 아니라면 전부 재시도 */
|
|
210
213
|
if (reDeliveryCount <= (staticRetryCount - 1)) { /** 재시도 횟수가 있고, 재시도 횟수보다 적을 경우, 0부터 카운팅 되므로 -1 */
|
|
211
214
|
channel.nack(message, false, true);
|
|
212
215
|
message.properties.replyTo = undefined; /** replyTo가 존재하면 sendToQueue가 호출되므로, 삭제해주기 */
|
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.
|
|
3
|
+
"version": "1.5.1-jun.0",
|
|
4
4
|
"author": "Yolo Co., Ltd.",
|
|
5
5
|
"description": "Yolo commonization module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -17,6 +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": "^2.1.0",
|
|
20
21
|
"@yolo-croket-dev/redis": "^1.0.23",
|
|
21
22
|
"@yolo-croket-dev/swagger": "^0.0.7",
|
|
22
23
|
"axios": "^1.1.3",
|