Closed dentarg closed 10 months ago
This started to happen with v0.8.2, the spec above run fine with versions before.
I can't reproduce the issue in Ruby (with the Bunny client)
#!/usr/bin/env ruby
$stdout.sync = true
$stderr.sync = true
begin
require "bunny"
rescue LoadError
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "bunny"
end
end
puts "Bunny version: #{Bunny::VERSION}"
def connect_and_publish(url:, queue_name:, message:)
connection = Bunny.new(url, {})
connection.start
channel = connection.create_channel
channel.confirm_select # enable publisher confirms
queue = channel.queue(queue_name, durable: true)
queue.publish(%(time="#{Time.now}" message="#{message}"), :key => queue.name)
channel.wait_for_confirms
connection.close
puts "Message published with confirm, connection closed (#{message})"
end
def connect_and_consume(url:, queue_name:)
puts "Starting connection for consume loop"
connection = Bunny.new(url, {})
connection.start
channel = connection.create_channel
queue = channel.queue(queue_name, durable: true)
queue.subscribe(consumer_tag: "foo bar", block: false) do |_delivery_info, _properties, body|
channel.basic_ack(delivery_info.delivery_tag.to_i)
puts "Consumed message: #{body}"
end
puts "Sleeping..."
sleep 1
end
url = ENV.fetch("AMQP_URL", "amqp://127.0.0.1:5672")
queue_name = "pub-sub-ruby-test-queue"
message = "hello from ruby pub-sub"
5.times do
connect_and_publish(url:, queue_name:, message:)
end
connect_and_consume(url:, queue_name:)
$ AMQP_URL=amqp://127.0.0.1:5673 ruby pub-sub.rb
Bunny version: 2.22.0
Message published with confirm, connection closed (hello from ruby pub-sub)
Message published with confirm, connection closed (hello from ruby pub-sub)
Message published with confirm, connection closed (hello from ruby pub-sub)
Message published with confirm, connection closed (hello from ruby pub-sub)
Message published with confirm, connection closed (hello from ruby pub-sub)
Starting connection for consume loop
Sleeping...
Consumed message: time="2023-10-17 21:29:02 +0200" message="hello from ruby pub-sub"
Consumed message: time="2023-10-17 21:29:02 +0200" message="hello from ruby pub-sub"
Consumed message: time="2023-10-17 21:29:02 +0200" message="hello from ruby pub-sub"
Consumed message: time="2023-10-17 21:29:02 +0200" message="hello from ruby pub-sub"
Consumed message: time="2023-10-17 21:29:02 +0200" message="hello from ruby pub-sub"
Saw the Crystal example work one time 🤯 amqproxy v0.8.12 that I had run the Ruby code above against
$ AMQP_URL=amqp://127.0.0.1:5673 CRYSTAL_OPTS="--link-flags=-Wl,-ld_classic" crystal pub-sub.cr
AMQP::Client::VERSION: 1.0.12
published
published
published
published
published
consumed: 1 (message from specs)
consumed: 2 (message from specs)
consumed: 3 (message from specs)
consumed: 4 (message from specs)
consumed: 5 (message from specs)
.
Finished in 545.47 milliseconds
1 examples, 0 failures, 0 errors, 0 pending
basic_consume
isnt blocking, so youre disconnecting as soon as you've subscribed, causing a race condition, is that intended?
In the ruby code youre sleeping 1s after starting to consume, but not in the crystal code
Thanks, that was not intended and explains the issues.
While working on a spec for #135 I noticed the following.
Running this code:
Against AMQProxy (reproduces with v0.8.12, v0.8.13 hangs after the first publish)
Against RabbitMQ it works well: