Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/internal_events/amqp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,28 @@ pub mod sink {
});
}
}

#[derive(Debug)]
pub struct AmqpNackError;

impl InternalEvent for AmqpNackError {
fn emit(self) {
let deliver_reason = "Received Negative Acknowledgement from AMQP broker.";
Comment thread
dsmith3197 marked this conversation as resolved.
Outdated
error!(
message = deliver_reason,
error_type = error_type::ACKNOWLEDGMENT_FAILED,
stage = error_stage::SENDING,
internal_log_rate_limit = true,
);
counter!(
"component_errors_total", 1,
"error_type" => error_type::ACKNOWLEDGMENT_FAILED,
"stage" => error_stage::SENDING,
);
emit!(ComponentEventsDropped::<UNINTENTIONAL> {
count: 1,
reason: deliver_reason
});
}
}
}
17 changes: 6 additions & 11 deletions src/sinks/amqp/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The main tower service that takes the request created by the request builder
//! and sends it to `AMQP`.
use crate::{
internal_events::sink::{AmqpAcknowledgementError, AmqpDeliveryError},
internal_events::sink::{AmqpAcknowledgementError, AmqpDeliveryError, AmqpNackError},
sinks::prelude::*,
};
use bytes::Bytes;
Expand Down Expand Up @@ -92,6 +92,9 @@ pub(super) enum AmqpError {

#[snafu(display("Failed AMQP request: {}", error))]
AmqpDeliveryFailed { error: lapin::Error },

#[snafu(display("Recieved Negative Acknowledgement from AMQP broker."))]
Comment thread Fixed
AmqpNack,
}

impl Service<AmqpRequest> for AmqpService {
Expand All @@ -109,11 +112,6 @@ impl Service<AmqpRequest> for AmqpService {
let channel = Arc::clone(&self.channel);

Box::pin(async move {
channel
.confirm_select(lapin::options::ConfirmSelectOptions::default())
.await
.unwrap();

let byte_size = req.body.len();
let fut = channel
.basic_publish(
Expand All @@ -128,11 +126,8 @@ impl Service<AmqpRequest> for AmqpService {
match fut {
Ok(result) => match result.await {
Ok(lapin::publisher_confirm::Confirmation::Nack(_)) => {
warn!("Received Negative Acknowledgement from AMQP server.");
Ok(AmqpResponse {
json_size: req.metadata.into_events_estimated_json_encoded_byte_size(),
byte_size,
})
emit!(AmqpNackError);
Err(AmqpError::AmqpNack)
Comment thread
neuronull marked this conversation as resolved.
Outdated
}
Err(error) => {
// TODO: In due course the caller could emit these on error.
Expand Down
1 change: 1 addition & 0 deletions src/sinks/amqp/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl AmqpSink {
.await
.map_err(|e| BuildError::AmqpCreateFailed { source: e })?;

// Enable confirmations on the channel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good find!

channel
.confirm_select(ConfirmSelectOptions::default())
.await
Expand Down