Skip to content

Commit

Permalink
Don't log error when blocking consume (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
spuun authored Sep 13, 2024
1 parent ce0b0df commit 8c5077e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Blocking consume won't log errors anymore. [#47](https://github.com/cloudamqp/amqp-client.cr/pull/47)

## [1.2.6] - 2024-08-23

### Added
Expand Down
8 changes: 5 additions & 3 deletions src/amqp-client/channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class AMQP::Client
deliveries = ::Channel(DeliverMessage).new(@prefetch_count.to_i32)
@consumers[ok.consumer_tag] = deliveries
work_pool.times do |i|
spawn consume(ok.consumer_tag, deliveries, done, i, blk),
spawn consume(ok.consumer_tag, deliveries, done, i, !block, blk),
same_thread: i.zero?, # only force put the first fiber on same thread
name: "AMQPconsumer##{ok.consumer_tag} ##{i}"
end
Expand All @@ -429,13 +429,15 @@ class AMQP::Client
ok.consumer_tag
end

private def consume(consumer_tag, deliveries, done, i, blk)
private def consume(consumer_tag, deliveries, done, i, log_errors, blk)
Log.context.set channel_id: @id.to_i, consumer: consumer_tag, worker: i
while msg = deliveries.receive?
begin
blk.call(msg)
rescue ex
Log.error(exception: ex) { "Uncaught exception in consumer, closing channel" }
if log_errors
Log.error(exception: ex) { "Uncaught exception in consumer, closing channel" }
end
close("Uncaught exception in consumer #{consumer_tag}", 500) rescue nil
done.send(ex) rescue nil
return
Expand Down

0 comments on commit 8c5077e

Please sign in to comment.