-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.ts
More file actions
87 lines (82 loc) · 2.98 KB
/
config.ts
File metadata and controls
87 lines (82 loc) · 2.98 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { TMQConstants } from "./constant";
export class TmqConfig {
url: URL | null = null;
sql_url: URL | null = null;
user: string | null = null;
password: string | null = null;
token: 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.CONNECT_TOKEN:
this.token = value;
this.otherConfigs.set(key, 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;
}
if (this.token) {
this.url.searchParams.set("bearer_token", this.token);
} else {
const bearerToken = this.url.searchParams.get("bearer_token");
if (bearerToken) {
this.token = bearerToken;
this.otherConfigs.set(TMQConstants.CONNECT_TOKEN, bearerToken);
} else {
this.url.searchParams.delete("bearer_token");
}
}
this.sql_url = new URL(this.url);
this.sql_url.pathname = "/ws";
this.url.pathname = "/rest/tmq";
}
}
}