-
Notifications
You must be signed in to change notification settings - Fork 9
/
event-store-heroes.module.ts
110 lines (109 loc) · 3.66 KB
/
event-store-heroes.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { Logger, Module } from '@nestjs/common';
import { CommandHandlers } from './commands/handlers';
import { EventHandlers } from './events/handlers';
import { HeroesGameController } from './heroes.controller';
import { QueryHandlers } from './queries/handlers';
import { HeroRepository } from './repository/hero.repository';
import { HeroesGameSagas } from './sagas/heroes.sagas';
import { heroesEvents } from './events/impl';
import { EventStoreCqrsModule, IEventStoreEventOptions } from '../../../src';
import { HealthController } from './health.controller';
import { TerminusModule } from '@nestjs/terminus';
import { LoggerModule } from 'nestjs-pino-stackdriver/dist';
import * as util from 'util';
@Module({
imports: [
TerminusModule,
EventStoreCqrsModule.register(
{
credentials: {
username: process.env.EVENTSTORE_CREDENTIALS_USERNAME || 'admin',
password: process.env.EVENTSTORE_CREDENTIALS_PASSWORD || 'changeit',
},
tcp: {
host: process.env.EVENTSTORE_TCP_HOST || 'localhost',
port: +process.env.EVENTSTORE_TCP_PORT || 11113,
},
http: {
host: process.env.EVENTSTORE_HTTP_HOST || 'http://localhost',
port: +process.env.EVENTSTORE_HTTP_PORT || 22113,
},
tcpConnectionName: 'connection-hero-event-handler-and-saga',
options: {
log: {
debug: (str, ...args) => {
Logger.warn(util.format(str, ...args), 'EventStoreCore');
},
info: (str, ...args) => {
Logger.log(util.format(str, ...args), 'EventStoreCore');
},
error: (str, ...args) => {
Logger.log(util.format(str, ...args), 'EventStoreCore');
},
},
// Buffer events if remote is slow or not available
maxQueueSize: 100_000,
maxRetries: 10_000,
operationTimeout: 5_000,
operationTimeoutCheckPeriod: 1_000,
// Fail fast on connect
clientConnectionTimeout: 2_000,
failOnNoServerResponse: true,
// Try to reconnect every 10s for 30mn
maxReconnections: 200,
reconnectionDelay: 10_000,
// Production heartbeat
heartbeatInterval: 10_000,
heartbeatTimeout: 3_000,
},
onTcpDisconnected: () => {
Logger.error(
`Connection to eventstore lost`,
undefined,
'EventStoreCore',
);
//process.exit(137);
},
onTcpConnected: () => {},
},
{
eventMapper: (data, options: IEventStoreEventOptions) => {
let className = `${options.eventType}`;
if (!heroesEvents[className]) {
return false;
}
Logger.debug(
`Build ${className} received from stream ${options.eventStreamId} with id ${options.eventId}`,
);
return new heroesEvents[className](data, options);
},
subscriptions: {
persistent: [
{
// Event stream category (before the -)
stream: '$ce-hero',
group: 'data',
autoAck: false,
bufferSize: 1,
// Subscription is created with this options
options: {
resolveLinktos: true,
minCheckPointCount: 1,
},
},
],
},
},
),
LoggerModule.forRoot(),
],
controllers: [HealthController, HeroesGameController],
providers: [
HeroRepository,
...CommandHandlers,
...EventHandlers,
...QueryHandlers,
HeroesGameSagas,
],
})
export class EventStoreHeroesModule {}