|
10 | 10 | import time |
11 | 11 | import argparse |
12 | 12 | from confluent_kafka import Consumer, KafkaException |
13 | | - |
14 | | - |
| 13 | +from datetime import datetime |
| 14 | +from rich.prompt import Prompt |
15 | 15 | from rich.table import Table |
16 | 16 | from rich.live import Live |
17 | 17 | from rich.console import Console |
|
21 | 21 |
|
22 | 22 | disable_ssl_warnings = True |
23 | 23 | console = Console(width=200) |
24 | | - |
| 24 | +now = datetime.now() |
| 25 | +current_time = now.strftime("%H:%M:%S") |
25 | 26 |
|
26 | 27 | from confluent_kafka import Consumer, KafkaException |
27 | 28 |
|
| 29 | +earliest_latest = Prompt.ask("Msgs from earliest or latest:", default="earliest") |
| 30 | + |
28 | 31 | # Define the Kafka consumer configuration. |
29 | 32 | config = { |
30 | 33 | 'bootstrap.servers': 'localhost:9092', # replace with your Kafka broker(s) |
31 | | - 'group.id': "w4", # replace with your consumer group |
32 | | - 'auto.offset.reset': 'earliest' # can be set to 'earliest' or 'latest' |
| 34 | + 'group.id': f"view_asset_events:{current_time}", # replace with your consumer group |
| 35 | + 'auto.offset.reset': earliest_latest # can be set to 'earliest' or 'latest' |
33 | 36 | } |
34 | 37 |
|
35 | 38 | # Initialize a Kafka consumer. |
|
54 | 57 |
|
55 | 58 | type_name = event["elementHeader"]["type"]["typeName"] |
56 | 59 | origin = event["elementHeader"]["origin"]["sourceServer"] |
57 | | - # classifications = event['elementHeader']["classifications"] |
58 | | - # classification_md = "" |
59 | | - # for c in classifications: |
60 | | - # cp = c.get("classificationProperties", None) |
61 | | - # if cp is not None: |
62 | | - # cl_name = c["classificationProperties"].get("name", None) |
63 | | - # cl = cl_name if not None else c["classificationName"] |
64 | | - # classification_md += f"* classifications: {cl}\n" |
65 | 60 |
|
66 | 61 | element_properties = event["elementProperties"] |
67 | 62 | element_properties_keys = element_properties.keys() |
|
72 | 67 | console.rule(style= "[bold red]") |
73 | 68 | console.rule(f"\tMessage TimeStamp: {event_time}\t eventType: {event_type}\t typeName: {type_name}\t guid: {guid}") |
74 | 69 | msg = ( |
75 | | - # f"classifications: \n{classification_md}\n" |
| 70 | + |
76 | 71 | f"properties: \n{props}\n\n") |
77 | 72 | msg = Markdown(msg) |
78 | | - # msg = json.dumps(event, indent=4) |
| 73 | + |
79 | 74 | console.print(msg) |
80 | 75 | finally: |
81 | 76 | # Close down consumer to commit final offsets. |
|
0 commit comments