mirror of
https://github.com/perstarkse/minne.git
synced 2026-09-15 22:41:46 +02:00
feat: refactoring complete?
This commit is contained in:
+23
-18
@@ -1,11 +1,9 @@
|
||||
use lapin::{
|
||||
options::*, publisher_confirm::Confirmation, BasicProperties,
|
||||
};
|
||||
use lapin::{options::*, publisher_confirm::Confirmation, BasicProperties};
|
||||
|
||||
use crate::models::ingress_object::IngressObject;
|
||||
use crate::ingress::types::ingress_object::IngressObject;
|
||||
|
||||
use super::{RabbitMQCommon, RabbitMQCommonTrait, RabbitMQConfig, RabbitMQError};
|
||||
use tracing::{info, error};
|
||||
use tracing::{error, info};
|
||||
|
||||
/// Struct to publish messages to RabbitMQ.
|
||||
pub struct RabbitMQProducer {
|
||||
@@ -27,7 +25,7 @@ impl RabbitMQProducer {
|
||||
let common = RabbitMQCommon::new(config).await?;
|
||||
common.declare_exchange(config, false).await?;
|
||||
|
||||
Ok(Self {
|
||||
Ok(Self {
|
||||
common,
|
||||
exchange_name: config.exchange.clone(),
|
||||
routing_key: config.routing_key.clone(),
|
||||
@@ -39,19 +37,23 @@ impl RabbitMQProducer {
|
||||
/// # Arguments
|
||||
/// * `self` - Reference to self
|
||||
/// * `ingress_object` - A initialized IngressObject
|
||||
///
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Result<Confirmation, RabbitMQError>` - Confirmation of sent message or error
|
||||
pub async fn publish(&self, ingress_object: &IngressObject) -> Result<Confirmation, RabbitMQError> {
|
||||
pub async fn publish(
|
||||
&self,
|
||||
ingress_object: &IngressObject,
|
||||
) -> Result<Confirmation, RabbitMQError> {
|
||||
// Serialize IngressObject to JSON
|
||||
let payload = serde_json::to_vec(ingress_object)
|
||||
.map_err(|e| {
|
||||
error!("Serialization Error: {}", e);
|
||||
RabbitMQError::PublishError(format!("Serialization Error: {}", e))
|
||||
})?;
|
||||
|
||||
let payload = serde_json::to_vec(ingress_object).map_err(|e| {
|
||||
error!("Serialization Error: {}", e);
|
||||
RabbitMQError::PublishError(format!("Serialization Error: {}", e))
|
||||
})?;
|
||||
|
||||
// Publish the serialized payload to RabbitMQ
|
||||
let confirmation = self.common.channel
|
||||
let confirmation = self
|
||||
.common
|
||||
.channel
|
||||
.basic_publish(
|
||||
&self.exchange_name,
|
||||
&self.routing_key,
|
||||
@@ -69,9 +71,12 @@ impl RabbitMQProducer {
|
||||
error!("Publish Confirmation Error: {}", e);
|
||||
RabbitMQError::PublishError(format!("Publish Confirmation Error: {}", e))
|
||||
})?;
|
||||
|
||||
info!("Published IngressObject to exchange '{}' with routing key '{}'", self.exchange_name, self.routing_key);
|
||||
|
||||
|
||||
info!(
|
||||
"Published IngressObject to exchange '{}' with routing key '{}'",
|
||||
self.exchange_name, self.routing_key
|
||||
);
|
||||
|
||||
Ok(confirmation)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user