bunny 1.7.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE.md +18 -0
- data/.gitignore +6 -1
- data/.rspec +1 -3
- data/.travis.yml +21 -14
- data/CONTRIBUTING.md +132 -0
- data/ChangeLog.md +745 -1
- data/Gemfile +13 -13
- data/LICENSE +1 -1
- data/README.md +41 -75
- data/Rakefile +54 -0
- data/bunny.gemspec +4 -10
- data/docker-compose.yml +28 -0
- data/docker/Dockerfile +24 -0
- data/docker/apt/preferences.d/erlang +3 -0
- data/docker/apt/sources.list.d/bintray.rabbitmq.list +2 -0
- data/docker/docker-entrypoint.sh +26 -0
- data/docker/rabbitmq.conf +29 -0
- data/examples/connection/automatic_recovery_with_basic_get.rb +1 -1
- data/examples/connection/automatic_recovery_with_client_named_queues.rb +1 -1
- data/examples/connection/automatic_recovery_with_multiple_consumers.rb +1 -1
- data/examples/connection/automatic_recovery_with_republishing.rb +1 -1
- data/examples/connection/automatic_recovery_with_server_named_queues.rb +1 -1
- data/examples/connection/channel_level_exception.rb +1 -9
- data/examples/connection/disabled_automatic_recovery.rb +1 -1
- data/examples/connection/heartbeat.rb +1 -1
- data/examples/consumers/high_and_low_priority.rb +1 -1
- data/examples/guides/extensions/alternate_exchange.rb +2 -0
- data/examples/guides/getting_started/hello_world.rb +2 -0
- data/examples/guides/getting_started/weathr.rb +2 -0
- data/examples/guides/queues/one_off_consumer.rb +2 -0
- data/examples/guides/queues/redeliveries.rb +2 -0
- data/lib/bunny.rb +6 -2
- data/lib/bunny/channel.rb +192 -109
- data/lib/bunny/channel_id_allocator.rb +6 -4
- data/lib/bunny/concurrent/continuation_queue.rb +34 -13
- data/lib/bunny/consumer_work_pool.rb +34 -6
- data/lib/bunny/cruby/socket.rb +29 -16
- data/lib/bunny/cruby/ssl_socket.rb +20 -7
- data/lib/bunny/exceptions.rb +7 -1
- data/lib/bunny/exchange.rb +11 -7
- data/lib/bunny/get_response.rb +1 -1
- data/lib/bunny/heartbeat_sender.rb +3 -2
- data/lib/bunny/jruby/socket.rb +23 -6
- data/lib/bunny/jruby/ssl_socket.rb +5 -0
- data/lib/bunny/queue.rb +12 -10
- data/lib/bunny/reader_loop.rb +31 -18
- data/lib/bunny/session.rb +389 -134
- data/lib/bunny/test_kit.rb +14 -0
- data/lib/bunny/timeout.rb +1 -12
- data/lib/bunny/transport.rb +114 -67
- data/lib/bunny/version.rb +1 -1
- data/repl +1 -1
- data/spec/config/rabbitmq.conf +13 -0
- data/spec/higher_level_api/integration/basic_ack_spec.rb +154 -22
- data/spec/higher_level_api/integration/basic_cancel_spec.rb +77 -11
- data/spec/higher_level_api/integration/basic_consume_spec.rb +60 -55
- data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +6 -6
- data/spec/higher_level_api/integration/basic_get_spec.rb +31 -7
- data/spec/higher_level_api/integration/basic_nack_spec.rb +22 -19
- data/spec/higher_level_api/integration/basic_publish_spec.rb +11 -100
- data/spec/higher_level_api/integration/basic_qos_spec.rb +32 -4
- data/spec/higher_level_api/integration/basic_reject_spec.rb +94 -16
- data/spec/higher_level_api/integration/basic_return_spec.rb +4 -4
- data/spec/higher_level_api/integration/channel_close_spec.rb +51 -10
- data/spec/higher_level_api/integration/channel_open_spec.rb +12 -12
- data/spec/higher_level_api/integration/connection_recovery_spec.rb +412 -286
- data/spec/higher_level_api/integration/connection_spec.rb +284 -134
- data/spec/higher_level_api/integration/connection_stop_spec.rb +31 -19
- data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +17 -17
- data/spec/higher_level_api/integration/dead_lettering_spec.rb +14 -14
- data/spec/higher_level_api/integration/exchange_bind_spec.rb +5 -5
- data/spec/higher_level_api/integration/exchange_declare_spec.rb +32 -31
- data/spec/higher_level_api/integration/exchange_delete_spec.rb +12 -12
- data/spec/higher_level_api/integration/exchange_unbind_spec.rb +5 -5
- data/spec/higher_level_api/integration/exclusive_queue_spec.rb +5 -5
- data/spec/higher_level_api/integration/heartbeat_spec.rb +4 -4
- data/spec/higher_level_api/integration/message_properties_access_spec.rb +49 -49
- data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +2 -2
- data/spec/higher_level_api/integration/publisher_confirms_spec.rb +92 -27
- data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +19 -19
- data/spec/higher_level_api/integration/queue_bind_spec.rb +23 -23
- data/spec/higher_level_api/integration/queue_declare_spec.rb +129 -34
- data/spec/higher_level_api/integration/queue_delete_spec.rb +2 -2
- data/spec/higher_level_api/integration/queue_purge_spec.rb +5 -5
- data/spec/higher_level_api/integration/queue_unbind_spec.rb +6 -6
- data/spec/higher_level_api/integration/read_only_consumer_spec.rb +9 -9
- data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +10 -10
- data/spec/higher_level_api/integration/tls_connection_spec.rb +218 -112
- data/spec/higher_level_api/integration/toxiproxy_spec.rb +76 -0
- data/spec/higher_level_api/integration/tx_commit_spec.rb +1 -1
- data/spec/higher_level_api/integration/tx_rollback_spec.rb +1 -1
- data/spec/higher_level_api/integration/with_channel_spec.rb +2 -2
- data/spec/issues/issue100_spec.rb +11 -12
- data/spec/issues/issue141_spec.rb +13 -14
- data/spec/issues/issue202_spec.rb +1 -1
- data/spec/issues/issue224_spec.rb +5 -5
- data/spec/issues/issue465_spec.rb +32 -0
- data/spec/issues/issue549_spec.rb +30 -0
- data/spec/issues/issue78_spec.rb +21 -24
- data/spec/issues/issue83_spec.rb +5 -6
- data/spec/issues/issue97_spec.rb +44 -45
- data/spec/lower_level_api/integration/basic_cancel_spec.rb +15 -16
- data/spec/lower_level_api/integration/basic_consume_spec.rb +20 -21
- data/spec/spec_helper.rb +2 -19
- data/spec/stress/channel_close_stress_spec.rb +3 -3
- data/spec/stress/channel_open_stress_spec.rb +4 -4
- data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +7 -7
- data/spec/stress/concurrent_consumers_stress_spec.rb +18 -16
- data/spec/stress/concurrent_publishers_stress_spec.rb +16 -19
- data/spec/stress/connection_open_close_spec.rb +9 -9
- data/spec/stress/merry_go_round_spec.rb +105 -0
- data/spec/tls/ca_certificate.pem +27 -16
- data/spec/tls/ca_key.pem +52 -27
- data/spec/tls/client_certificate.pem +27 -16
- data/spec/tls/client_key.pem +49 -25
- data/spec/tls/generate-server-cert.sh +8 -0
- data/spec/tls/server-openssl.cnf +10 -0
- data/spec/tls/server.csr +16 -0
- data/spec/tls/server_certificate.pem +27 -16
- data/spec/tls/server_key.pem +49 -25
- data/spec/toxiproxy_helper.rb +28 -0
- data/spec/unit/bunny_spec.rb +5 -5
- data/spec/unit/concurrent/atomic_fixnum_spec.rb +6 -6
- data/spec/unit/concurrent/condition_spec.rb +8 -8
- data/spec/unit/concurrent/linked_continuation_queue_spec.rb +2 -2
- data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +16 -16
- data/spec/unit/exchange_recovery_spec.rb +39 -0
- data/spec/unit/version_delivery_tag_spec.rb +3 -3
- metadata +42 -35
- data/lib/bunny/system_timer.rb +0 -20
- data/spec/config/rabbitmq.config +0 -18
- data/spec/higher_level_api/integration/basic_recover_spec.rb +0 -18
- data/spec/higher_level_api/integration/confirm_select_spec.rb +0 -19
- data/spec/higher_level_api/integration/consistent_hash_exchange_spec.rb +0 -50
- data/spec/higher_level_api/integration/merry_go_round_spec.rb +0 -85
- data/spec/stress/long_running_consumer_spec.rb +0 -83
- data/spec/tls/cacert.pem +0 -18
- data/spec/tls/client_cert.pem +0 -18
- data/spec/tls/server_cert.pem +0 -18
- data/spec/unit/system_timer_spec.rb +0 -10
@@ -0,0 +1,76 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "../../toxiproxy_helper"
|
3
|
+
|
4
|
+
if ::Toxiproxy.running?
|
5
|
+
describe Bunny::Channel, "#basic_publish" do
|
6
|
+
include RabbitMQ::Toxiproxy
|
7
|
+
|
8
|
+
after :each do
|
9
|
+
@connection.close if @connection.open?
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when the the connection detects missed heartbeats with automatic recovery" do
|
13
|
+
before(:each) do
|
14
|
+
setup_toxiproxy
|
15
|
+
@connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
|
16
|
+
host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: true)
|
17
|
+
@connection.start
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:queue_name) { "bunny.basic.publish.queue#{rand}" }
|
21
|
+
|
22
|
+
it "raises a ConnectionClosedError" do
|
23
|
+
ch = @connection.create_channel
|
24
|
+
begin
|
25
|
+
rabbitmq_toxiproxy.down do
|
26
|
+
sleep 2
|
27
|
+
expect { ch.default_exchange.publish("", :routing_key => queue_name) }.to raise_error(Bunny::ConnectionClosedError)
|
28
|
+
end
|
29
|
+
ensure
|
30
|
+
cleanup_toxiproxy
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the the connection detects missed heartbeats without automatic recovery" do
|
36
|
+
before(:each) do
|
37
|
+
setup_toxiproxy
|
38
|
+
@connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
|
39
|
+
host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: false, threaded: false)
|
40
|
+
@connection.start
|
41
|
+
end
|
42
|
+
|
43
|
+
it "does not raise an exception on session thread" do
|
44
|
+
rabbitmq_toxiproxy.down do
|
45
|
+
sleep 5
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "recovery attempt limit that's exceeded" do
|
51
|
+
before(:each) do
|
52
|
+
setup_toxiproxy
|
53
|
+
@connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
|
54
|
+
host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: true, network_recovery_interval: 1,
|
55
|
+
recovery_attempts: 2, reset_recovery_attempts_after_reconnection: true,
|
56
|
+
disconnect_timeout: 1)
|
57
|
+
@connection.start
|
58
|
+
end
|
59
|
+
|
60
|
+
it "permanently closes connection" do
|
61
|
+
expect(@connection.open?).to be(true)
|
62
|
+
|
63
|
+
rabbitmq_toxiproxy.down do
|
64
|
+
sleep 5
|
65
|
+
end
|
66
|
+
# give the connection one last chance to recover
|
67
|
+
sleep 3
|
68
|
+
|
69
|
+
expect(@connection.open?).to be(false)
|
70
|
+
expect(@connection.closed?).to be(true)
|
71
|
+
end
|
72
|
+
end # context
|
73
|
+
end # describe
|
74
|
+
else
|
75
|
+
puts "Toxiproxy isn't running, some examples will be skipped"
|
76
|
+
end
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Bunny::Channel, "#tx_commit" do
|
4
4
|
let(:connection) do
|
5
|
-
c = Bunny.new(:
|
5
|
+
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
6
|
c.start
|
7
7
|
c
|
8
8
|
end
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Bunny::Channel, "#tx_rollback" do
|
4
4
|
let(:connection) do
|
5
|
-
c = Bunny.new(:
|
5
|
+
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
6
|
c.start
|
7
7
|
c
|
8
8
|
end
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Bunny::Channel, "#with_channel" do
|
4
4
|
let(:connection) do
|
5
|
-
c = Bunny.new(:
|
5
|
+
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
6
|
c.start
|
7
7
|
c
|
8
8
|
end
|
@@ -20,6 +20,6 @@ describe Bunny::Channel, "#with_channel" do
|
|
20
20
|
end
|
21
21
|
rescue Exception
|
22
22
|
end
|
23
|
-
ch.
|
23
|
+
expect(ch).to be_closed
|
24
24
|
end
|
25
25
|
end
|
@@ -2,18 +2,17 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
unless ENV["CI"]
|
4
4
|
describe Bunny::Channel, "#basic_publish" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
c
|
5
|
+
before :all do
|
6
|
+
@connection = Bunny.new(username: "bunny_gem",
|
7
|
+
password: "bunny_password",
|
8
|
+
vhost: "bunny_testbed",
|
9
|
+
write_timeout: 0,
|
10
|
+
read_timeout: 0)
|
11
|
+
@connection.start
|
13
12
|
end
|
14
13
|
|
15
14
|
after :all do
|
16
|
-
connection.close if connection.open?
|
15
|
+
@connection.close if @connection.open?
|
17
16
|
end
|
18
17
|
|
19
18
|
|
@@ -22,15 +21,15 @@ unless ENV["CI"]
|
|
22
21
|
let(:m) { 10 }
|
23
22
|
|
24
23
|
it "successfully publishers them all" do
|
25
|
-
ch = connection.create_channel
|
24
|
+
ch = @connection.create_channel
|
26
25
|
|
27
|
-
q = ch.queue("", :
|
26
|
+
q = ch.queue("", exclusive: true)
|
28
27
|
x = ch.default_exchange
|
29
28
|
|
30
29
|
body = "x" * 1024
|
31
30
|
m.times do |i|
|
32
31
|
n.times do
|
33
|
-
x.publish(body, :
|
32
|
+
x.publish(body, routing_key: q.name)
|
34
33
|
end
|
35
34
|
puts "Published #{i * n} 1K messages..."
|
36
35
|
end
|
@@ -1,43 +1,42 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Registering 2nd exclusive consumer on queue" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
c
|
4
|
+
before :all do
|
5
|
+
@connection = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
|
6
|
+
@connection.start
|
8
7
|
end
|
9
8
|
|
10
9
|
after :each do
|
11
|
-
connection.close if connection.open?
|
10
|
+
@connection.close if @connection.open?
|
12
11
|
end
|
13
12
|
|
14
13
|
|
15
14
|
it "raises a meaningful exception" do
|
16
15
|
xs = []
|
17
16
|
|
18
|
-
ch1 = connection.create_channel
|
19
|
-
ch2 = connection.create_channel
|
17
|
+
ch1 = @connection.create_channel
|
18
|
+
ch2 = @connection.create_channel
|
20
19
|
q1 = ch1.queue("", :auto_delete => true)
|
21
20
|
q2 = ch2.queue(q1.name, :auto_delete => true, :passive => true)
|
22
21
|
|
23
|
-
c1 = q1.subscribe(:
|
22
|
+
c1 = q1.subscribe(exclusive: true) do |_, _, payload|
|
24
23
|
xs << payload
|
25
24
|
end
|
26
25
|
sleep 0.1
|
27
26
|
|
28
|
-
|
29
|
-
q2.subscribe(:
|
27
|
+
expect do
|
28
|
+
q2.subscribe(exclusive: true) do |_, _, _|
|
30
29
|
end
|
31
|
-
end.
|
30
|
+
end.to raise_error(Bunny::AccessRefused)
|
32
31
|
|
33
|
-
ch1.
|
34
|
-
ch2.
|
32
|
+
expect(ch1).to be_open
|
33
|
+
expect(ch2).to be_closed
|
35
34
|
|
36
35
|
q1.publish("abc")
|
37
36
|
sleep 0.1
|
38
37
|
|
39
38
|
# verify that the first consumer is fine
|
40
|
-
xs.
|
39
|
+
expect(xs).to eq ["abc"]
|
41
40
|
|
42
41
|
q1.delete
|
43
42
|
end
|
@@ -4,7 +4,7 @@ describe Bunny::Session do
|
|
4
4
|
context "with unreachable host" do
|
5
5
|
it "raises Bunny::TCPConnectionFailed" do
|
6
6
|
begin
|
7
|
-
conn = Bunny.new(:hostname => "
|
7
|
+
conn = Bunny.new(:hostname => "127.0.0.254", :port => 1433)
|
8
8
|
conn.start
|
9
9
|
|
10
10
|
fail "expected 192.192.192.192 to be unreachable"
|
@@ -5,7 +5,7 @@ unless ENV["CI"]
|
|
5
5
|
describe "Message framing implementation" do
|
6
6
|
let(:connection) do
|
7
7
|
c = Bunny.new(:user => "bunny_gem",
|
8
|
-
:
|
8
|
+
password: "bunny_password",
|
9
9
|
:vhost => "bunny_testbed",
|
10
10
|
:port => ENV.fetch("RABBITMQ_PORT", 5672))
|
11
11
|
c.start
|
@@ -21,17 +21,17 @@ unless ENV["CI"]
|
|
21
21
|
it "successfully frames the message" do
|
22
22
|
ch = connection.create_channel
|
23
23
|
|
24
|
-
q = ch.queue("", :
|
24
|
+
q = ch.queue("", exclusive: true)
|
25
25
|
x = ch.default_exchange
|
26
26
|
|
27
27
|
as = ("a" * 272179)
|
28
|
-
x.publish(as, :
|
28
|
+
x.publish(as, routing_key: q.name, persistent: true)
|
29
29
|
|
30
30
|
sleep(1)
|
31
|
-
q.message_count.
|
31
|
+
expect(q.message_count).to eq 1
|
32
32
|
|
33
33
|
_, _, payload = q.pop
|
34
|
-
payload.bytesize.
|
34
|
+
expect(payload.bytesize).to eq as.bytesize
|
35
35
|
|
36
36
|
ch.close
|
37
37
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Bunny::Session do
|
5
|
+
let(:connection) do
|
6
|
+
c = Bunny.new(
|
7
|
+
user: 'bunny_gem', password: 'bunny_password',
|
8
|
+
vhost: 'bunny_testbed',
|
9
|
+
port: ENV.fetch('RABBITMQ_PORT', 5672)
|
10
|
+
)
|
11
|
+
c.start
|
12
|
+
c
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'after the connection has been manually closed' do
|
16
|
+
before :each do
|
17
|
+
connection.close
|
18
|
+
end
|
19
|
+
|
20
|
+
after :each do
|
21
|
+
connection.close if connection.open?
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#create_channel' do
|
25
|
+
it 'should raise an exception' do
|
26
|
+
expect {
|
27
|
+
connection.create_channel
|
28
|
+
}.to raise_error(Bunny::ConnectionAlreadyClosed)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bunny::Session do
|
4
|
+
context 'when retry attempts have been exhausted' do
|
5
|
+
let(:io) { StringIO.new } # keep test output clear
|
6
|
+
|
7
|
+
def create_session
|
8
|
+
described_class.new(
|
9
|
+
host: 'fake.host',
|
10
|
+
recovery_attempts: 0,
|
11
|
+
connection_timeout: 0,
|
12
|
+
network_recovery_interval: 0,
|
13
|
+
logfile: io,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'closes the session' do
|
18
|
+
session = create_session
|
19
|
+
session.handle_network_failure(StandardError.new)
|
20
|
+
expect(session.closed?).to be true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'stops the reader loop' do
|
24
|
+
session = create_session
|
25
|
+
reader_loop = session.reader_loop
|
26
|
+
session.handle_network_failure(StandardError.new)
|
27
|
+
expect(reader_loop.stopping?).to be true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/issues/issue78_spec.rb
CHANGED
@@ -2,20 +2,17 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
unless ENV["CI"]
|
4
4
|
describe Bunny::Queue, "#subscribe" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
let(:connection2) do
|
11
|
-
c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
|
12
|
-
c.start
|
13
|
-
c
|
5
|
+
before :all do
|
6
|
+
@connection1 = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
|
7
|
+
@connection1.start
|
8
|
+
@connection2 = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
|
9
|
+
@connection2.start
|
14
10
|
end
|
15
11
|
|
16
12
|
after :all do
|
17
|
-
connection1.
|
18
|
-
|
13
|
+
[@connection1, @connection2].select { |c| !!c }.each do |c|
|
14
|
+
c.close if c.open?
|
15
|
+
end
|
19
16
|
end
|
20
17
|
|
21
18
|
|
@@ -23,20 +20,20 @@ unless ENV["CI"]
|
|
23
20
|
it "consumes messages" do
|
24
21
|
delivered_data = []
|
25
22
|
|
26
|
-
ch1 = connection1.create_channel
|
27
|
-
ch2 = connection1.create_channel
|
23
|
+
ch1 = @connection1.create_channel
|
24
|
+
ch2 = @connection1.create_channel
|
28
25
|
|
29
|
-
q = ch1.queue("", :
|
30
|
-
q.subscribe(
|
26
|
+
q = ch1.queue("", exclusive: true)
|
27
|
+
q.subscribe(manual_ack: false) do |delivery_info, properties, payload|
|
31
28
|
delivered_data << payload
|
32
29
|
end
|
33
30
|
sleep 0.5
|
34
31
|
|
35
32
|
x = ch2.default_exchange
|
36
|
-
x.publish("abc", :
|
33
|
+
x.publish("abc", routing_key: q.name)
|
37
34
|
sleep 0.7
|
38
35
|
|
39
|
-
delivered_data.
|
36
|
+
expect(delivered_data).to eq ["abc"]
|
40
37
|
|
41
38
|
ch1.close
|
42
39
|
ch2.close
|
@@ -49,23 +46,23 @@ unless ENV["CI"]
|
|
49
46
|
it "consumes messages" do
|
50
47
|
delivered_data = []
|
51
48
|
|
52
|
-
ch1 = connection1.create_channel
|
53
|
-
ch2 = connection1.create_channel
|
49
|
+
ch1 = @connection1.create_channel
|
50
|
+
ch2 = @connection1.create_channel
|
54
51
|
|
55
|
-
q = ch1.queue(queue_name, :
|
52
|
+
q = ch1.queue(queue_name, exclusive: true)
|
56
53
|
x = ch2.default_exchange
|
57
54
|
3.times do |i|
|
58
|
-
x.publish("data#{i}", :
|
55
|
+
x.publish("data#{i}", routing_key: queue_name)
|
59
56
|
end
|
60
57
|
sleep 0.7
|
61
|
-
q.message_count.
|
58
|
+
expect(q.message_count).to eq 3
|
62
59
|
|
63
|
-
q.subscribe(
|
60
|
+
q.subscribe(manual_ack: false) do |delivery_info, properties, payload|
|
64
61
|
delivered_data << payload
|
65
62
|
end
|
66
63
|
sleep 0.7
|
67
64
|
|
68
|
-
delivered_data.
|
65
|
+
expect(delivered_data).to eq ["data0", "data1", "data2"]
|
69
66
|
|
70
67
|
ch1.close
|
71
68
|
ch2.close
|
data/spec/issues/issue83_spec.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Bunny::Channel, "#open" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
c
|
4
|
+
before :all do
|
5
|
+
@connection = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
|
6
|
+
@connection.start
|
8
7
|
end
|
9
8
|
|
10
9
|
after :all do
|
11
|
-
connection.close if connection.open?
|
10
|
+
@connection.close if @connection.open?
|
12
11
|
end
|
13
12
|
|
14
13
|
|
15
14
|
it "properly resets channel exception state" do
|
16
|
-
ch = connection.create_channel
|
15
|
+
ch = @connection.create_channel
|
17
16
|
|
18
17
|
begin
|
19
18
|
ch.queue("bunny.tests.does.not.exist", :passive => true)
|
data/spec/issues/issue97_spec.rb
CHANGED
@@ -1,33 +1,32 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Message framing implementation" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
c
|
4
|
+
before :all do
|
5
|
+
@connection = Bunny.new(username: "bunny_gem",
|
6
|
+
password: "bunny_password",
|
7
|
+
vhost: "bunny_testbed",
|
8
|
+
port: ENV.fetch("RABBITMQ_PORT", 5672))
|
9
|
+
@connection.start
|
11
10
|
end
|
12
11
|
|
13
12
|
after :all do
|
14
|
-
connection.close if connection.open?
|
13
|
+
@connection.close if @connection.open?
|
15
14
|
end
|
16
15
|
|
17
16
|
|
18
17
|
unless ENV["CI"]
|
19
18
|
context "with payload ~ 248K in size including non-ASCII characters" do
|
20
19
|
it "successfully frames the message" do
|
21
|
-
ch = connection.create_channel
|
20
|
+
ch = @connection.create_channel
|
22
21
|
|
23
|
-
q = ch.queue("", :
|
22
|
+
q = ch.queue("", exclusive: true)
|
24
23
|
x = ch.default_exchange
|
25
24
|
|
26
25
|
body = IO.read("spec/issues/issue97_attachment.json")
|
27
|
-
x.publish(body, :
|
26
|
+
x.publish(body, routing_key: q.name, persistent: true)
|
28
27
|
|
29
28
|
sleep(1)
|
30
|
-
q.message_count.
|
29
|
+
expect(q.message_count).to eq 1
|
31
30
|
|
32
31
|
q.purge
|
33
32
|
ch.close
|
@@ -38,19 +37,19 @@ describe "Message framing implementation" do
|
|
38
37
|
|
39
38
|
context "with payload of several MBs in size" do
|
40
39
|
it "successfully frames the message" do
|
41
|
-
ch = connection.create_channel
|
40
|
+
ch = @connection.create_channel
|
42
41
|
|
43
|
-
q = ch.queue("", :
|
42
|
+
q = ch.queue("", exclusive: true)
|
44
43
|
x = ch.default_exchange
|
45
44
|
|
46
45
|
as = ("a" * (1024 * 1024 * 4 + 2823777))
|
47
|
-
x.publish(as, :
|
46
|
+
x.publish(as, routing_key: q.name, persistent: true)
|
48
47
|
|
49
48
|
sleep(1)
|
50
|
-
q.message_count.
|
49
|
+
expect(q.message_count).to eq 1
|
51
50
|
|
52
51
|
_, _, payload = q.pop
|
53
|
-
payload.bytesize.
|
52
|
+
expect(payload.bytesize).to eq as.bytesize
|
54
53
|
|
55
54
|
ch.close
|
56
55
|
end
|
@@ -60,23 +59,23 @@ describe "Message framing implementation" do
|
|
60
59
|
|
61
60
|
context "with empty message body" do
|
62
61
|
it "successfully publishes the message" do
|
63
|
-
ch = connection.create_channel
|
62
|
+
ch = @connection.create_channel
|
64
63
|
|
65
|
-
q = ch.queue("", :
|
64
|
+
q = ch.queue("", exclusive: true)
|
66
65
|
x = ch.default_exchange
|
67
66
|
|
68
|
-
x.publish("", :
|
67
|
+
x.publish("", routing_key: q.name, persistent: true)
|
69
68
|
|
70
69
|
sleep(1)
|
71
|
-
q.message_count.
|
70
|
+
expect(q.message_count).to eq 1
|
72
71
|
|
73
72
|
envelope, headers, payload = q.pop
|
74
73
|
|
75
|
-
payload.
|
74
|
+
expect(payload).to eq ""
|
76
75
|
|
77
|
-
headers[:content_type].
|
78
|
-
headers[:delivery_mode].
|
79
|
-
headers[:priority].
|
76
|
+
expect(headers[:content_type]).to eq "application/octet-stream"
|
77
|
+
expect(headers[:delivery_mode]).to eq 2
|
78
|
+
expect(headers[:priority]).to eq 0
|
80
79
|
|
81
80
|
ch.close
|
82
81
|
end
|
@@ -85,16 +84,16 @@ describe "Message framing implementation" do
|
|
85
84
|
|
86
85
|
context "with payload being 2 bytes less than 128K bytes in size" do
|
87
86
|
it "successfully frames the message" do
|
88
|
-
ch = connection.create_channel
|
87
|
+
ch = @connection.create_channel
|
89
88
|
|
90
|
-
q = ch.queue("", :
|
89
|
+
q = ch.queue("", exclusive: true)
|
91
90
|
x = ch.default_exchange
|
92
91
|
|
93
92
|
as = "a" * (1024 * 128 - 2)
|
94
|
-
x.publish(as, :
|
93
|
+
x.publish(as, routing_key: q.name, persistent: true)
|
95
94
|
|
96
95
|
sleep(1)
|
97
|
-
q.message_count.
|
96
|
+
expect(q.message_count).to eq 1
|
98
97
|
|
99
98
|
q.purge
|
100
99
|
ch.close
|
@@ -103,16 +102,16 @@ describe "Message framing implementation" do
|
|
103
102
|
|
104
103
|
context "with payload being 1 byte less than 128K bytes in size" do
|
105
104
|
it "successfully frames the message" do
|
106
|
-
ch = connection.create_channel
|
105
|
+
ch = @connection.create_channel
|
107
106
|
|
108
|
-
q = ch.queue("", :
|
107
|
+
q = ch.queue("", exclusive: true)
|
109
108
|
x = ch.default_exchange
|
110
109
|
|
111
110
|
as = "a" * (1024 * 128 - 1)
|
112
|
-
x.publish(as, :
|
111
|
+
x.publish(as, routing_key: q.name, persistent: true)
|
113
112
|
|
114
113
|
sleep(1)
|
115
|
-
q.message_count.
|
114
|
+
expect(q.message_count).to eq 1
|
116
115
|
|
117
116
|
q.purge
|
118
117
|
ch.close
|
@@ -121,16 +120,16 @@ describe "Message framing implementation" do
|
|
121
120
|
|
122
121
|
context "with payload being exactly 128K bytes in size" do
|
123
122
|
it "successfully frames the message" do
|
124
|
-
ch = connection.create_channel
|
123
|
+
ch = @connection.create_channel
|
125
124
|
|
126
|
-
q = ch.queue("", :
|
125
|
+
q = ch.queue("", exclusive: true)
|
127
126
|
x = ch.default_exchange
|
128
127
|
|
129
128
|
as = "a" * (1024 * 128)
|
130
|
-
x.publish(as, :
|
129
|
+
x.publish(as, routing_key: q.name, persistent: true)
|
131
130
|
|
132
131
|
sleep(1)
|
133
|
-
q.message_count.
|
132
|
+
expect(q.message_count).to eq 1
|
134
133
|
|
135
134
|
q.purge
|
136
135
|
ch.close
|
@@ -140,16 +139,16 @@ describe "Message framing implementation" do
|
|
140
139
|
|
141
140
|
context "with payload being 1 byte greater than 128K bytes in size" do
|
142
141
|
it "successfully frames the message" do
|
143
|
-
ch = connection.create_channel
|
142
|
+
ch = @connection.create_channel
|
144
143
|
|
145
|
-
q = ch.queue("", :
|
144
|
+
q = ch.queue("", exclusive: true)
|
146
145
|
x = ch.default_exchange
|
147
146
|
|
148
147
|
as = "a" * (1024 * 128 + 1)
|
149
|
-
x.publish(as, :
|
148
|
+
x.publish(as, routing_key: q.name, persistent: true)
|
150
149
|
|
151
150
|
sleep(1)
|
152
|
-
q.message_count.
|
151
|
+
expect(q.message_count).to eq 1
|
153
152
|
|
154
153
|
q.purge
|
155
154
|
ch.close
|
@@ -158,16 +157,16 @@ describe "Message framing implementation" do
|
|
158
157
|
|
159
158
|
context "with payload being 2 bytes greater than 128K bytes in size" do
|
160
159
|
it "successfully frames the message" do
|
161
|
-
ch = connection.create_channel
|
160
|
+
ch = @connection.create_channel
|
162
161
|
|
163
|
-
q = ch.queue("", :
|
162
|
+
q = ch.queue("", exclusive: true)
|
164
163
|
x = ch.default_exchange
|
165
164
|
|
166
165
|
as = "a" * (1024 * 128 + 2)
|
167
|
-
x.publish(as, :
|
166
|
+
x.publish(as, routing_key: q.name, persistent: true)
|
168
167
|
|
169
168
|
sleep(1)
|
170
|
-
q.message_count.
|
169
|
+
expect(q.message_count).to eq 1
|
171
170
|
|
172
171
|
q.purge
|
173
172
|
ch.close
|