-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathconsumer.py
43 lines (36 loc) · 961 Bytes
/
consumer.py
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
import click
from confluent_kafka import Consumer
from kaskade.configs import BOOTSTRAP_SERVERS, GROUP_ID, AUTO_OFFSET_RESET, EARLIEST
@click.command()
@click.option(
"--bootstrap-servers", default="localhost:19092", help="Bootstrap servers.", show_default=True
)
def main(bootstrap_servers: str) -> None:
topics = [
"string",
"integer",
"long",
"float",
"double",
"boolean",
"null",
"json",
"protobuf",
"avro",
]
consumer = Consumer(
{
BOOTSTRAP_SERVERS: bootstrap_servers,
GROUP_ID: "sandbox.consumer",
AUTO_OFFSET_RESET: EARLIEST,
}
)
consumer.subscribe(topics, on_assign=lambda a, b: print("Assignment completed"))
while True:
try:
consumer.poll(timeout=1.0)
except KeyboardInterrupt:
break
consumer.close()
if __name__ == "__main__":
main()