UNPKG

@jiaxinjiang/nest-nacos

Version:

Nacos component for NestJs.

55 lines 2.73 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.NacosInstanceService = void 0; const common_1 = require("@nestjs/common"); const nacos_instance_constants_1 = require("./nacos.instance.constants"); const naming_1 = require("../naming"); let NacosInstanceService = class NacosInstanceService { constructor(config, namingService) { this.config = config; this.namingService = namingService; this.config.instance.metadata = this.config.instance.metadata || { node_version: process.version, }; } get metadata() { return this.config.instance.metadata; } async onApplicationBootstrap() { const { instance, subscribers } = this.config; await this.namingService.registerInstance(instance.serviceName, instance, instance.groupName); subscribers.forEach(service => { this.namingService.subscribe(Object.assign({}, service), (hosts, logger) => { if (hosts.length > 0) { logger.info(`New service detected: ${JSON.stringify(hosts)}`); } }); }); } async onApplicationShutdown() { const { instance, subscribers } = this.config; await this.namingService.deregisterInstance(instance.serviceName, instance, instance.groupName); subscribers.forEach(service => { this.namingService.unSubscribe(Object.assign({}, service)); }); } }; NacosInstanceService = __decorate([ common_1.Injectable(), __param(0, common_1.Inject(nacos_instance_constants_1.NACOS_INSTANCE_OPTION)), __metadata("design:paramtypes", [Object, naming_1.NacosNamingService]) ], NacosInstanceService); exports.NacosInstanceService = NacosInstanceService; //# sourceMappingURL=nacos.instance.service.js.map