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

Bugfix: make sure AMQPSource reconnects #754

Merged
merged 2 commits into from
Aug 20, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Prevet a queue that's overflowing to consume too much resources
- Dead-lettering loop when publishing to a delayed exchange's internal queue [#748](https://github.com/cloudamqp/lavinmq/pull/748)
- Exchange federation tried to bind to upstream's default exchange
- Shovel AMQP source didn't reconnect on network failures

### Changed

Expand Down
32 changes: 32 additions & 0 deletions spec/shovel_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,38 @@ end

describe LavinMQ::Shovel do
describe "AMQP" do
describe "Source" do
it "will stop and raise on unexpected disconnect" do
with_amqp_server do |s|
source = LavinMQ::Shovel::AMQPSource.new(
"spec",
[URI.parse(s.amqp_url)],
"source",
direct_user: s.users.direct_user
)

wg = WaitGroup.new(1)
exception : Exception? = nil
spawn do
source.start
wg.done
source.each do
end
rescue ex
exception = ex
ensure
wg.done
end
wg.wait # wait for source to start
wg.add 1
s.vhosts["/"].connections.each &.close("spec")
wg.wait # wait for exception to be rescued
source.started?.should be_false
exception.should be_a AMQP::Client::Connection::ClosedException
end
end
end

it "will wait to ack all msgs before deleting it self" do
with_amqp_server do |s|
source = LavinMQ::Shovel::AMQPSource.new(
Expand Down
7 changes: 4 additions & 3 deletions src/lavinmq/shovel/shovel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ module LavinMQ
end
rescue e : FailedDeliveryError
msg.reject
rescue e
stop
raise e
end
rescue e
Log.warn { "name=#{@name} #{e.message}" }
stop
raise e
end
end

Expand Down
Loading