@@ -2,24 +2,36 @@ use crate::types::{BundleEvent, UserOpEvent};
22use anyhow:: Result ;
33use async_trait:: async_trait;
44use rdkafka:: producer:: { FutureProducer , FutureRecord } ;
5- use serde_json;
65use tracing:: { debug, error, info} ;
76
7+ /// Trait for publishing bundle events.
88#[ async_trait]
99pub trait BundleEventPublisher : Send + Sync {
10+ /// Publishes a single bundle event.
1011 async fn publish ( & self , event : BundleEvent ) -> Result < ( ) > ;
1112
13+ /// Publishes multiple bundle events.
1214 async fn publish_all ( & self , events : Vec < BundleEvent > ) -> Result < ( ) > ;
1315}
1416
17+ /// Publishes bundle events to Kafka.
1518#[ derive( Clone ) ]
1619pub struct KafkaBundleEventPublisher {
1720 producer : FutureProducer ,
1821 topic : String ,
1922}
2023
24+ impl std:: fmt:: Debug for KafkaBundleEventPublisher {
25+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
26+ f. debug_struct ( "KafkaBundleEventPublisher" )
27+ . field ( "topic" , & self . topic )
28+ . finish_non_exhaustive ( )
29+ }
30+ }
31+
2132impl KafkaBundleEventPublisher {
22- pub fn new ( producer : FutureProducer , topic : String ) -> Self {
33+ /// Creates a new Kafka bundle event publisher.
34+ pub const fn new ( producer : FutureProducer , topic : String ) -> Self {
2335 Self { producer, topic }
2436 }
2537
@@ -71,11 +83,13 @@ impl BundleEventPublisher for KafkaBundleEventPublisher {
7183 }
7284}
7385
74- #[ derive( Clone ) ]
86+ /// Publishes bundle events to logs (for testing/debugging).
87+ #[ derive( Clone , Debug ) ]
7588pub struct LoggingBundleEventPublisher ;
7689
7790impl LoggingBundleEventPublisher {
78- pub fn new ( ) -> Self {
91+ /// Creates a new logging bundle event publisher.
92+ pub const fn new ( ) -> Self {
7993 Self
8094 }
8195}
@@ -105,21 +119,34 @@ impl BundleEventPublisher for LoggingBundleEventPublisher {
105119 }
106120}
107121
122+ /// Trait for publishing user operation events.
108123#[ async_trait]
109124pub trait UserOpEventPublisher : Send + Sync {
125+ /// Publishes a single user operation event.
110126 async fn publish ( & self , event : UserOpEvent ) -> Result < ( ) > ;
111127
128+ /// Publishes multiple user operation events.
112129 async fn publish_all ( & self , events : Vec < UserOpEvent > ) -> Result < ( ) > ;
113130}
114131
132+ /// Publishes user operation events to Kafka.
115133#[ derive( Clone ) ]
116134pub struct KafkaUserOpEventPublisher {
117135 producer : FutureProducer ,
118136 topic : String ,
119137}
120138
139+ impl std:: fmt:: Debug for KafkaUserOpEventPublisher {
140+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
141+ f. debug_struct ( "KafkaUserOpEventPublisher" )
142+ . field ( "topic" , & self . topic )
143+ . finish_non_exhaustive ( )
144+ }
145+ }
146+
121147impl KafkaUserOpEventPublisher {
122- pub fn new ( producer : FutureProducer , topic : String ) -> Self {
148+ /// Creates a new Kafka user operation event publisher.
149+ pub const fn new ( producer : FutureProducer , topic : String ) -> Self {
123150 Self { producer, topic }
124151 }
125152
@@ -171,11 +198,13 @@ impl UserOpEventPublisher for KafkaUserOpEventPublisher {
171198 }
172199}
173200
174- #[ derive( Clone ) ]
201+ /// Publishes user operation events to logs (for testing/debugging).
202+ #[ derive( Clone , Debug ) ]
175203pub struct LoggingUserOpEventPublisher ;
176204
177205impl LoggingUserOpEventPublisher {
178- pub fn new ( ) -> Self {
206+ /// Creates a new logging user operation event publisher.
207+ pub const fn new ( ) -> Self {
179208 Self
180209 }
181210}
0 commit comments