Skip to content

Commit 7e551ab

Browse files
committed
latest updates
1 parent 4bba670 commit 7e551ab

1 file changed

Lines changed: 55 additions & 54 deletions

File tree

kafence/src/lib.rs

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl Kafence {
273273
materialize_loop(&self.client_id, &stream_consumer, &rocks_db).await
274274
}
275275

276-
async fn create_routed_stream(&self, mut recv: UnboundedReceiver<RouteInfo>) -> Result<()> {
276+
async fn create_routed_stream(&self, recv: UnboundedReceiver<RouteInfo>) -> Result<()> {
277277
create_route_topic_if_not_exists(&self.brokers, &self.topic_router).await?;
278278
let stream_consumer = create_consumer(
279279
&self.client_id,
@@ -317,59 +317,6 @@ async fn create_route_topic_if_not_exists(brokers: &str, topic: &str) -> anyhow:
317317
Ok(())
318318
}
319319

320-
// Kafka Producer
321-
// --------------
322-
323-
trait KafenceProducerContract<K, V> {
324-
async fn strong_consistency(&self, topic: &str, key: K, value: V);
325-
}
326-
327-
impl<K: ToBytes + Send + Sync + Clone + 'static, V: ToBytes + Send> KafenceProducerContract<K, V>
328-
for KafenceProducer
329-
{
330-
async fn strong_consistency(&self, topic: &str, key: K, value: V) {
331-
let record = FutureRecord::to(topic).key(&key).payload(&value);
332-
333-
self.producer
334-
.send(record, Duration::from_secs(5))
335-
.await
336-
.expect("record must be delivered");
337-
}
338-
}
339-
340-
async fn publish_route_info(
341-
brokers: &str,
342-
topic_router: &str,
343-
mut recv: UnboundedReceiver<RouteInfo>,
344-
) {
345-
while let Some(route_info) = recv.recv().await {
346-
let partitions = route_info.paritions.read().unwrap().iter().copied().collect::<Vec<_>>();
347-
println!("New Route info {:?}", route_info);
348-
match ClientConfig::new()
349-
.set("bootstrap.servers", brokers)
350-
.set("message.timeout.ms", "5000")
351-
.create::<FutureProducer>()
352-
{
353-
Ok(producer) => {
354-
for partition in partitions {
355-
let key = format!("{}:{}", topic_router, partition);
356-
let record = FutureRecord::to(topic_router)
357-
.key(&key)
358-
.payload(&route_info.service_host);
359-
360-
producer
361-
.send(record, Duration::from_secs(5))
362-
.await
363-
.expect("record must be delivered");
364-
}
365-
}
366-
Err(e) => {
367-
println!("Error creating Kafka producer. Caused by {}", e);
368-
}
369-
}
370-
}
371-
}
372-
373320
type KafenceStreamConsumer = StreamConsumer<KafenceConsumerContext>;
374321

375322
fn create_consumer<C>(
@@ -507,6 +454,60 @@ fn materialized_key(message: &BorrowedMessage<'_>) -> Vec<u8> {
507454
}
508455
}
509456

457+
458+
// Kafka Producer
459+
// --------------
460+
461+
trait KafenceProducerContract<K, V> {
462+
async fn strong_consistency(&self, topic: &str, key: K, value: V);
463+
}
464+
465+
impl<K: ToBytes + Send + Sync + Clone + 'static, V: ToBytes + Send> KafenceProducerContract<K, V>
466+
for KafenceProducer
467+
{
468+
async fn strong_consistency(&self, topic: &str, key: K, value: V) {
469+
470+
let record = FutureRecord::to(topic).key(&key).payload(&value);
471+
472+
self.producer
473+
.send(record, Duration::from_secs(5))
474+
.await
475+
.expect("record must be delivered");
476+
}
477+
}
478+
async fn publish_route_info(
479+
brokers: &str,
480+
topic_router: &str,
481+
mut recv: UnboundedReceiver<RouteInfo>,
482+
) {
483+
while let Some(route_info) = recv.recv().await {
484+
let partitions = route_info.paritions.read().unwrap().iter().copied().collect::<Vec<_>>();
485+
println!("New Route info {:?}", route_info);
486+
match ClientConfig::new()
487+
.set("bootstrap.servers", brokers)
488+
.set("message.timeout.ms", "5000")
489+
.create::<FutureProducer>()
490+
{
491+
Ok(producer) => {
492+
for partition in partitions {
493+
let key = format!("{}:{}", topic_router, partition);
494+
let record = FutureRecord::to(topic_router)
495+
.key(&key)
496+
.payload(&route_info.service_host);
497+
498+
producer
499+
.send(record, Duration::from_secs(5))
500+
.await
501+
.expect("record must be delivered");
502+
}
503+
}
504+
Err(e) => {
505+
println!("Error creating Kafka producer. Caused by {}", e);
506+
}
507+
}
508+
}
509+
}
510+
510511
#[cfg(test)]
511512
mod test {
512513
use crate::{Kafence, KafenceProducerContract};

0 commit comments

Comments
 (0)