@@ -7,36 +7,18 @@ use rdkafka::{
77 consumer:: { Consumer , StreamConsumer } ,
88 message:: Message ,
99} ;
10- use std:: fs;
1110use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
11+ use tips_core:: kafka:: load_kafka_config_from_file;
1212use tokio:: time:: sleep;
13- use tracing:: { debug, error, info } ;
13+ use tracing:: { debug, error} ;
1414
1515pub fn create_kafka_consumer ( kafka_properties_file : & str ) -> Result < StreamConsumer > {
16- let client_config = load_kafka_config_from_file ( kafka_properties_file) ?;
16+ let client_config =
17+ ClientConfig :: from_iter ( load_kafka_config_from_file ( kafka_properties_file) ?) ;
1718 let consumer: StreamConsumer = client_config. create ( ) ?;
1819 Ok ( consumer)
1920}
2021
21- fn load_kafka_config_from_file ( properties_file_path : & str ) -> Result < ClientConfig > {
22- let kafka_properties = fs:: read_to_string ( properties_file_path) ?;
23- info ! ( "Kafka properties:\n {}" , kafka_properties) ;
24-
25- let mut client_config = ClientConfig :: new ( ) ;
26-
27- for line in kafka_properties. lines ( ) {
28- let line = line. trim ( ) ;
29- if line. is_empty ( ) || line. starts_with ( '#' ) {
30- continue ;
31- }
32- if let Some ( ( key, value) ) = line. split_once ( '=' ) {
33- client_config. set ( key. trim ( ) , value. trim ( ) ) ;
34- }
35- }
36-
37- Ok ( client_config)
38- }
39-
4022pub fn assign_topic_partition ( consumer : & StreamConsumer , topic : & str ) -> Result < ( ) > {
4123 let mut tpl = TopicPartitionList :: new ( ) ;
4224 tpl. add_partition ( topic, 0 ) ;
@@ -57,14 +39,14 @@ pub trait EventReader {
5739 async fn commit ( & mut self ) -> Result < ( ) > ;
5840}
5941
60- pub struct KafkaMempoolReader {
42+ pub struct KafkaAuditLogReader {
6143 consumer : StreamConsumer ,
6244 topic : String ,
6345 last_message_offset : Option < i64 > ,
6446 last_message_partition : Option < i32 > ,
6547}
6648
67- impl KafkaMempoolReader {
49+ impl KafkaAuditLogReader {
6850 pub fn new ( consumer : StreamConsumer , topic : String ) -> Result < Self > {
6951 consumer. subscribe ( & [ & topic] ) ?;
7052 Ok ( Self {
@@ -77,7 +59,7 @@ impl KafkaMempoolReader {
7759}
7860
7961#[ async_trait]
80- impl EventReader for KafkaMempoolReader {
62+ impl EventReader for KafkaAuditLogReader {
8163 async fn read_event ( & mut self ) -> Result < Event > {
8264 match self . consumer . recv ( ) . await {
8365 Ok ( message) => {
@@ -143,7 +125,7 @@ impl EventReader for KafkaMempoolReader {
143125 }
144126}
145127
146- impl KafkaMempoolReader {
128+ impl KafkaAuditLogReader {
147129 pub fn topic ( & self ) -> & str {
148130 & self . topic
149131 }
0 commit comments