compiling code

This commit is contained in:
Thilo Behnke
2022-06-19 11:15:11 +02:00
parent 336ae38838
commit 1e0785ca16
2 changed files with 10 additions and 9 deletions

View File

@@ -58,24 +58,24 @@ impl EventWriterImpl for KafkaDefaultEventWriterImpl {
fn write_events<T>(events: Vec<Event>, producer: &mut Producer<T>) -> Result<(), String> where T : Partitioner {
let mut records_without_key = vec![];
let mut records_with_key = vec![];
for event in events {
for event in events.iter() {
match &event.key {
Some(key) => {
let record = Record::from_key_value(event.topic.as_str(), key.clone(), event.msg.as_str());
let record = Record::from_key_value(&event.topic, key.clone(), event.msg.clone());
records_with_key.push(record);
}
None => {
let record = Record::from_value(event.topic.as_str(), event.msg.as_str());
let record = Record::from_value(&event.topic, event.msg.clone());
records_without_key.push(record);
}
}
}
let res_with_key = match producer.send_all::<String, &str>(&*records_with_key) {
let res_with_key = match producer.send_all::<String, String>(&*records_with_key) {
Ok(_) => Ok(()),
Err(e) => Err(format!("{}", e)),
};
let res_without_key = match producer.send_all(&*records_without_key) {
let res_without_key = match producer.send_all::<(), String>(&*records_without_key) {
Ok(_) => Ok(()),
Err(e) => Err(format!("{}", e)),
};

View File

@@ -304,10 +304,9 @@ impl GameObjectStateDTO {
}
}
// TODO: Wip - Refactor to function
fn write_events<T>(events: Vec<T>, topic: &str, event_writer: &mut SessionWriter) -> bool where T : Serialize + Debug {
let mut any_error = false;
let mut events = vec![];
let mut to_send = vec![];
for event in events {
let serialized = serde_json::to_string(&event);
if let Err(e) = serialized {
@@ -315,10 +314,12 @@ fn write_events<T>(events: Vec<T>, topic: &str, event_writer: &mut SessionWriter
any_error = true;
continue;
}
events.push(serialized.unwrap().as_str());
let serialized = serialized.unwrap();
to_send.push(serialized);
}
let write_res = event_writer.write_to_session(topic, events);
let to_send = to_send.iter().map(|e| e.as_str()).collect();
let write_res = event_writer.write_to_session(topic, to_send);
if let Err(e) = write_res {
eprintln!("Failed to write at least one event to topic {}: {:?}", "move", e);
any_error = true;