-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
/
kafka.context.ts
59 lines (51 loc) 路 1.02 KB
/
kafka.context.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
import { Consumer, KafkaMessage, Producer } from '../external/kafka.interface';
import { BaseRpcContext } from './base-rpc.context';
type KafkaContextArgs = [
message: KafkaMessage,
partition: number,
topic: string,
consumer: Consumer,
heartbeat: () => Promise<void>,
producer: Producer,
];
export class KafkaContext extends BaseRpcContext<KafkaContextArgs> {
constructor(args: KafkaContextArgs) {
super(args);
}
/**
* Returns the reference to the original message.
*/
getMessage() {
return this.args[0];
}
/**
* Returns the partition.
*/
getPartition() {
return this.args[1];
}
/**
* Returns the name of the topic.
*/
getTopic() {
return this.args[2];
}
/**
* Returns the Kafka consumer reference.
*/
getConsumer() {
return this.args[3];
}
/**
* Returns the Kafka heartbeat callback.
*/
getHeartbeat() {
return this.args[4];
}
/**
* Returns the Kafka producer reference,
*/
getProducer() {
return this.args[5];
}
}