eventstore-interconnect
Version:
Eventstore interconnector
63 lines • 3.42 kB
JavaScript
;
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.TCPEventStoreConnectionInitializerService = void 0;
const common_1 = require("@nestjs/common");
const node_eventstore_client_1 = require("node-eventstore-client");
const nanoid_1 = require("nanoid");
const constants_1 = require("../../../constants");
const connections_guards_1 = require("../../../connections-guards");
const logger_1 = require("../../../logger");
let TCPEventStoreConnectionInitializerService = class TCPEventStoreConnectionInitializerService {
constructor(configuration, connectionGuard, logger) {
this.configuration = configuration;
this.connectionGuard = connectionGuard;
this.logger = logger;
}
async init() {
const esConnectionConf = {
maxQueueSize: 100000,
maxRetries: 10000,
operationTimeout: 5000,
operationTimeoutCheckPeriod: 1000,
clientConnectionTimeout: 2000,
failOnNoServerResponse: true,
maxReconnections: 200,
reconnectionDelay: 10000,
heartbeatInterval: 10000,
heartbeatTimeout: 3000,
};
const tcpEndPoint = {
host: this.configuration.tcp.host,
port: this.configuration.tcp.port,
};
this.eventStoreNodeConnection = (0, node_eventstore_client_1.createConnection)(esConnectionConf, tcpEndPoint, this.configuration.tcpConnectionName ??
`${constants_1.INTERCONNECTION_CONNECTION_DEFAULT_NAME}-${(0, nanoid_1.nanoid)(11)}`);
await this.eventStoreNodeConnection.connect();
this.logger.log(`Starting to ping connection on ${tcpEndPoint.host}:${tcpEndPoint.port}...`);
await this.connectionGuard.startConnectionLinkPinger(this.eventStoreNodeConnection, this.configuration);
}
getConnectedClient() {
return this.eventStoreNodeConnection;
}
};
TCPEventStoreConnectionInitializerService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, common_1.Inject)(constants_1.CONNECTION_CONFIGURATION)),
__param(1, (0, common_1.Inject)(connections_guards_1.EVENTSTORE_CONNECTION_GUARD)),
__param(2, (0, common_1.Inject)(logger_1.LOGGER)),
__metadata("design:paramtypes", [Object, Object, common_1.Logger])
], TCPEventStoreConnectionInitializerService);
exports.TCPEventStoreConnectionInitializerService = TCPEventStoreConnectionInitializerService;
//# sourceMappingURL=tcp-event-store-connection-initializer.service.js.map