@@ -12,7 +12,7 @@ use jsonrpsee::{
1212 server:: { ServerBuilder , ServerHandle , TowerService } ,
1313} ;
1414use lazy_static:: lazy_static;
15- use log:: info;
15+ use log:: { error , info} ;
1616use prometheus:: { register_counter, register_int_counter, Counter , IntCounter } ;
1717use tap_core:: signed_message:: Eip712SignedMessage ;
1818use tap_graph:: { Receipt , ReceiptAggregateVoucher , SignedReceipt } ;
@@ -94,6 +94,7 @@ struct RpcImpl {
9494 wallet : PrivateKeySigner ,
9595 accepted_addresses : HashSet < Address > ,
9696 domain_separator : Eip712Domain ,
97+ kafka : Option < rdkafka:: producer:: ThreadedProducer < rdkafka:: producer:: DefaultProducerContext > > ,
9798}
9899
99100/// Helper method that checks if the given API version is supported.
@@ -254,6 +255,25 @@ impl v2::tap_aggregator_server::TapAggregator for RpcImpl {
254255 TOTAL_AGGREGATED_RECEIPTS . inc_by ( receipts_count) ;
255256 AGGREGATION_SUCCESS_COUNTER . inc ( ) ;
256257
258+ if let Some ( kafka) = & self . kafka {
259+ let topic = "gateway_ravs" ;
260+ let key = format ! (
261+ "{:?}:{:?}:{:?}" ,
262+ self . wallet. address( ) ,
263+ res. message. payer,
264+ res. message. allocationId,
265+ ) ;
266+ let payload = res. message . valueAggregate . to_string ( ) ;
267+ let result = kafka. send (
268+ rdkafka:: producer:: BaseRecord :: to ( topic)
269+ . key ( & key)
270+ . payload ( & payload) ,
271+ ) ;
272+ if let Err ( ( err, _) ) = result {
273+ error ! ( "error producing to {topic}: {err}" ) ;
274+ }
275+ }
276+
257277 let response = v2:: RavResponse {
258278 rav : Some ( res. into ( ) ) ,
259279 } ;
@@ -304,6 +324,7 @@ impl RpcServer for RpcImpl {
304324 }
305325}
306326
327+ #[ allow( clippy:: too_many_arguments) ]
307328pub async fn run_server (
308329 port : u16 ,
309330 wallet : PrivateKeySigner ,
@@ -312,12 +333,14 @@ pub async fn run_server(
312333 max_request_body_size : u32 ,
313334 max_response_body_size : u32 ,
314335 max_concurrent_connections : u32 ,
336+ kafka : Option < rdkafka:: producer:: ThreadedProducer < rdkafka:: producer:: DefaultProducerContext > > ,
315337) -> Result < ( JoinHandle < ( ) > , std:: net:: SocketAddr ) > {
316338 // Setting up the JSON RPC server
317339 let rpc_impl = RpcImpl {
318340 wallet,
319341 accepted_addresses,
320342 domain_separator,
343+ kafka,
321344 } ;
322345 let ( json_rpc_service, _) = create_json_rpc_service (
323346 rpc_impl. clone ( ) ,
@@ -508,6 +531,7 @@ mod tests {
508531 http_request_size_limit,
509532 http_response_size_limit,
510533 http_max_concurrent_connections,
534+ None ,
511535 )
512536 . await
513537 . unwrap ( ) ;
@@ -557,6 +581,7 @@ mod tests {
557581 http_request_size_limit,
558582 http_response_size_limit,
559583 http_max_concurrent_connections,
584+ None ,
560585 )
561586 . await
562587 . unwrap ( ) ;
@@ -637,6 +662,7 @@ mod tests {
637662 http_request_size_limit,
638663 http_response_size_limit,
639664 http_max_concurrent_connections,
665+ None ,
640666 )
641667 . await
642668 . unwrap ( ) ;
@@ -714,6 +740,7 @@ mod tests {
714740 http_request_size_limit,
715741 http_response_size_limit,
716742 http_max_concurrent_connections,
743+ None ,
717744 )
718745 . await
719746 . unwrap ( ) ;
@@ -805,6 +832,7 @@ mod tests {
805832 http_request_size_limit,
806833 http_response_size_limit,
807834 http_max_concurrent_connections,
835+ None ,
808836 )
809837 . await
810838 . unwrap ( ) ;
0 commit comments