-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: final tweaks to messenger (#86)
* feat: rename update_savepoint fn in suffix to update_offset_to_commit * feat: move MessengerProducerContext to its own file * feat: built whitelist actions using env variables * feat: move get_mut and get_meta function in messenger suffix to core suffix package * feat: Handle processing action error and marking items complete * feat: publish message in separate thread * chore: lint fix due to rust version update to 1.73
- Loading branch information
1 parent
f97e6f5
commit 86e1454
Showing
24 changed files
with
350 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use futures_executor::block_on; | ||
use log::{error, info}; | ||
use rdkafka::{producer::ProducerContext, ClientContext, Message}; | ||
use talos_messenger_core::{core::MessengerChannelFeedback, errors::MessengerActionError}; | ||
use tokio::sync::mpsc; | ||
|
||
#[derive(Debug)] | ||
pub struct MessengerProducerDeliveryOpaque { | ||
pub version: u64, | ||
pub total_publish_count: u32, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct MessengerProducerContext { | ||
pub tx_feedback_channel: mpsc::Sender<MessengerChannelFeedback>, | ||
} | ||
|
||
impl ClientContext for MessengerProducerContext {} | ||
impl ProducerContext for MessengerProducerContext { | ||
type DeliveryOpaque = Box<MessengerProducerDeliveryOpaque>; | ||
|
||
fn delivery(&self, delivery_result: &rdkafka::producer::DeliveryResult<'_>, delivery_opaque: Self::DeliveryOpaque) { | ||
let result = delivery_result.as_ref(); | ||
|
||
let version = delivery_opaque.version; | ||
|
||
match result { | ||
Ok(msg) => { | ||
info!("Message {:?} {:?}", msg.key(), msg.offset()); | ||
// Safe to ignore error check, as error occurs only if receiver is closed or dropped, which would happen if the thread receving has errored. In such a scenario, the publisher thread would also shutdown. | ||
if let Err(error) = block_on(self.tx_feedback_channel.send(MessengerChannelFeedback::Success(version, "kafka".to_string()))) { | ||
error!("[Messenger Producer Context] Error sending feedback for version={version} with error={error:?}"); | ||
}; | ||
} | ||
Err((publish_error, borrowed_message)) => { | ||
error!( | ||
"[Messenger Producer Context] Error for version={:?} \nerror={:?}", | ||
delivery_opaque.version, | ||
publish_error.to_string() | ||
); | ||
let messenger_error = MessengerActionError { | ||
kind: talos_messenger_core::errors::MessengerActionErrorKind::Publishing, | ||
reason: publish_error.to_string(), | ||
data: format!("version={version} message={:#?}", borrowed_message.detach()), | ||
}; | ||
// Safe to ignore error check, as error occurs only if receiver is closed or dropped, which would happen if the thread receving has errored. In such a scenario, the publisher thread would also shutdown. | ||
if let Err(send_error) = block_on(self.tx_feedback_channel.send(MessengerChannelFeedback::Error( | ||
version, | ||
"kafka".to_string(), | ||
Box::new(messenger_error), | ||
))) { | ||
error!("[Messenger Producer Context] Error sending error feedback for version={version} with \npublish_error={publish_error:?} \nchannel send_error={send_error:?}"); | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod context; | ||
pub mod models; | ||
pub mod producer; | ||
pub mod service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.