Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed Write Message Dispatch #82

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Adds in local changes made to code as 'hot fixes' that were never added to the Git repo.
* Adds in support for OL8 packaging
* Allows writers to move failed writers to separate queue to keep pipeline clear and allow for
examination later.

## GRNOC TSDS Services 1.6.9 -- Wed Mar 16 2022

Expand Down
30 changes: 20 additions & 10 deletions lib/GRNOC/TSDS/Writer/Worker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use constant MEASUREMENT_CACHE_EXPIRATION => 60 * 60;
use constant QUEUE_PREFETCH_COUNT => 5;
use constant QUEUE_FETCH_TIMEOUT => 10 * 1000;
use constant RECONNECT_TIMEOUT => 10;
use constant PENDING_QUEUE_CHANNEL => 1;
use constant FAILED_QUEUE_CHANNEL => 2;

### required attributes ###

Expand Down Expand Up @@ -215,7 +217,7 @@ sub _consume_loop {
try {

# reject the message and do NOT requeue it since its malformed JSON
$self->rabbit->reject( 1, $rabbit_message->{'delivery_tag'}, 0 );
$self->rabbit->reject( PENDING_QUEUE_CHANNEL, $rabbit_message->{'delivery_tag'}, 0 );
}

catch {
Expand All @@ -238,7 +240,7 @@ sub _consume_loop {
try {

# reject the message and do NOT requeue since its not properly formed
$self->rabbit->reject( 1, $rabbit_message->{'delivery_tag'}, 0 );
$self->rabbit->reject( PENDING_QUEUE_CHANNEL, $rabbit_message->{'delivery_tag'}, 0 );
}

catch {
Expand Down Expand Up @@ -270,8 +272,9 @@ sub _consume_loop {
$self->logger->debug( "Rejecting rabbit message, requeueing." );

try {

$self->rabbit->reject( 1, $rabbit_message->{'delivery_tag'}, 1 );
# push message to failed queue and ack the original message
$self->rabbit->publish( FAILED_QUEUE_CHANNEL, $self->queue . "_failed", $self->json->encode( \@$messages ), {'exchange' => ''} );
$self->rabbit->ack( PENDING_QUEUE_CHANNEL, $rabbit_message->{'delivery_tag'} );
}

catch {
Expand All @@ -290,7 +293,7 @@ sub _consume_loop {

try {

$self->rabbit->ack( 1, $rabbit_message->{'delivery_tag'} );
$self->rabbit->ack( PENDING_QUEUE_CHANNEL, $rabbit_message->{'delivery_tag'} );
}

catch {
Expand Down Expand Up @@ -1630,14 +1633,21 @@ sub _rabbit_connect {
my $connected = 0;

try {

my $rabbit = Net::AMQP::RabbitMQ->new();

$rabbit->connect( $rabbit_host, {'port' => $rabbit_port} );
$rabbit->channel_open( 1 );
$rabbit->queue_declare( 1, $rabbit_queue, {'auto_delete' => 0} );
$rabbit->basic_qos( 1, { prefetch_count => QUEUE_PREFETCH_COUNT } );
$rabbit->consume( 1, $rabbit_queue, {'no_ack' => 0} );

# open channel & declare queue for pending writes
$rabbit->channel_open( PENDING_QUEUE_CHANNEL );
$rabbit->queue_declare( PENDING_QUEUE_CHANNEL, $rabbit_queue, {'auto_delete' => 0} );
$rabbit->basic_qos( PENDING_QUEUE_CHANNEL, { prefetch_count => QUEUE_PREFETCH_COUNT } );

# open channel & declare queue for failed writes
$rabbit->channel_open( FAILED_QUEUE_CHANNEL );
$rabbit->queue_declare( FAILED_QUEUE_CHANNEL, $self->queue . "_failed", {'auto_delete' => 0} );

# start consuming messages
$rabbit->consume( PENDING_QUEUE_CHANNEL, $rabbit_queue, {'no_ack' => 0} );

$self->_set_rabbit( $rabbit );

Expand Down