-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.ts
More file actions
71 lines (66 loc) · 2.3 KB
/
config.ts
File metadata and controls
71 lines (66 loc) · 2.3 KB
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
import { TMQConstants } from "./constant";
export class TmqConfig {
url: URL | null = null;
sql_url: URL | null = null;
user: string | null = null;
password: string | null = null;
group_id: string | null = null;
client_id: string | null = null;
offset_rest: string | null = null;
topics?: Array<string>;
auto_commit: boolean = true;
auto_commit_interval_ms: number = 5 * 1000;
timeout: number = 5000;
otherConfigs: Map<string, any>;
constructor(wsConfig: Map<string, any>) {
this.otherConfigs = new Map();
for (const [key, value] of wsConfig) {
switch (key) {
case TMQConstants.WS_URL:
this.url = new URL(value);
break;
case TMQConstants.CONNECT_USER:
this.user = value;
break;
case TMQConstants.CONNECT_PASS:
this.password = value;
break;
case TMQConstants.GROUP_ID:
this.group_id = value;
break;
case TMQConstants.CLIENT_ID:
this.client_id = value;
break;
case TMQConstants.AUTO_OFFSET_RESET:
this.offset_rest = value;
break;
case TMQConstants.ENABLE_AUTO_COMMIT:
this.auto_commit = value;
break;
case TMQConstants.AUTO_COMMIT_INTERVAL_MS:
this.auto_commit_interval_ms = value;
break;
case TMQConstants.CONNECT_MESSAGE_TIMEOUT:
this.timeout = value;
break;
default:
this.otherConfigs.set(key, value);
}
}
if (this.url) {
if (this.user) {
this.url.username = this.user;
} else {
this.user = this.url.username;
}
if (this.password) {
this.url.password = this.password;
} else {
this.password = this.url.password;
}
this.sql_url = new URL(this.url);
this.sql_url.pathname = "/ws";
this.url.pathname = "/rest/tmq";
}
}
}