bunny 2.7.4 → 2.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +61 -35
- data/lib/bunny/channel.rb +186 -50
- data/lib/bunny/channel_id_allocator.rb +3 -1
- data/lib/bunny/consumer.rb +2 -2
- data/lib/bunny/consumer_work_pool.rb +2 -1
- data/lib/bunny/cruby/socket.rb +3 -0
- data/lib/bunny/cruby/ssl_socket.rb +6 -1
- data/lib/bunny/delivery_info.rb +1 -1
- data/lib/bunny/heartbeat_sender.rb +2 -1
- data/lib/bunny/jruby/ssl_socket.rb +5 -0
- data/lib/bunny/queue.rb +36 -8
- data/lib/bunny/reader_loop.rb +22 -10
- data/lib/bunny/session.rb +152 -65
- data/lib/bunny/test_kit.rb +14 -0
- data/lib/bunny/transport.rb +132 -49
- data/lib/bunny/version.rb +1 -1
- data/lib/bunny.rb +45 -4
- metadata +37 -225
- data/.github/ISSUE_TEMPLATE.md +0 -18
- data/.gitignore +0 -28
- data/.rspec +0 -1
- data/.travis.yml +0 -20
- data/.yardopts +0 -8
- data/CONTRIBUTING.md +0 -111
- data/ChangeLog.md +0 -1831
- data/Gemfile +0 -53
- data/LICENSE +0 -21
- data/Rakefile +0 -46
- data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
- data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
- data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
- data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
- data/benchmarks/channel_open.rb +0 -28
- data/benchmarks/mutex_and_monitor.rb +0 -42
- data/benchmarks/queue_declare.rb +0 -29
- data/benchmarks/queue_declare_and_bind.rb +0 -29
- data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
- data/benchmarks/synchronized_sorted_set.rb +0 -53
- data/benchmarks/write_vs_write_nonblock.rb +0 -49
- data/bin/ci/before_build +0 -46
- data/bunny.gemspec +0 -35
- data/docker/Dockerfile +0 -16
- data/docker/docker-entrypoint.sh +0 -37
- data/docker-compose.yml +0 -18
- data/examples/connection/authentication_failure.rb +0 -16
- data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
- data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
- data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
- data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
- data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
- data/examples/connection/channel_level_exception.rb +0 -27
- data/examples/connection/disabled_automatic_recovery.rb +0 -34
- data/examples/connection/heartbeat.rb +0 -17
- data/examples/connection/manually_reconnecting_consumer.rb +0 -23
- data/examples/connection/manually_reconnecting_publisher.rb +0 -28
- data/examples/connection/unknown_host.rb +0 -16
- data/examples/consumers/high_and_low_priority.rb +0 -50
- data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
- data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
- data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
- data/examples/guides/exchanges/mandatory_messages.rb +0 -30
- data/examples/guides/extensions/alternate_exchange.rb +0 -30
- data/examples/guides/extensions/basic_nack.rb +0 -33
- data/examples/guides/extensions/connection_blocked.rb +0 -35
- data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
- data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
- data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
- data/examples/guides/extensions/per_message_ttl.rb +0 -36
- data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
- data/examples/guides/extensions/publisher_confirms.rb +0 -28
- data/examples/guides/extensions/queue_lease.rb +0 -26
- data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
- data/examples/guides/getting_started/blabbr.rb +0 -27
- data/examples/guides/getting_started/hello_world.rb +0 -22
- data/examples/guides/getting_started/weathr.rb +0 -49
- data/examples/guides/queues/one_off_consumer.rb +0 -25
- data/examples/guides/queues/redeliveries.rb +0 -81
- data/profiling/basic_publish/with_4K_messages.rb +0 -33
- data/repl +0 -3
- data/spec/config/enabled_plugins +0 -1
- data/spec/config/rabbitmq.config +0 -19
- data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
- data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
- data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -349
- data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
- data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
- data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
- data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
- data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
- data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
- data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
- data/spec/higher_level_api/integration/channel_close_spec.rb +0 -25
- data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
- data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -471
- data/spec/higher_level_api/integration/connection_spec.rb +0 -559
- data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
- data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
- data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
- data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
- data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
- data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
- data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
- data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
- data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
- data/spec/higher_level_api/integration/merry_go_round_spec.rb +0 -85
- data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
- data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
- data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
- data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
- data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
- data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -221
- data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
- data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
- data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
- data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
- data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
- data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -222
- data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
- data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
- data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
- data/spec/issues/issue100_spec.rb +0 -42
- data/spec/issues/issue141_spec.rb +0 -43
- data/spec/issues/issue202_spec.rb +0 -15
- data/spec/issues/issue224_spec.rb +0 -40
- data/spec/issues/issue465_spec.rb +0 -32
- data/spec/issues/issue78_spec.rb +0 -72
- data/spec/issues/issue83_spec.rb +0 -30
- data/spec/issues/issue97_attachment.json +0 -1
- data/spec/issues/issue97_spec.rb +0 -175
- data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
- data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
- data/spec/spec_helper.rb +0 -51
- data/spec/stress/channel_close_stress_spec.rb +0 -64
- data/spec/stress/channel_open_stress_spec.rb +0 -84
- data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
- data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
- data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
- data/spec/stress/connection_open_close_spec.rb +0 -52
- data/spec/stress/long_running_consumer_spec.rb +0 -84
- data/spec/tls/ca_certificate.pem +0 -29
- data/spec/tls/ca_key.pem +0 -52
- data/spec/tls/client_certificate.pem +0 -29
- data/spec/tls/client_key.pem +0 -51
- data/spec/tls/generate-server-cert.sh +0 -8
- data/spec/tls/server-openssl.cnf +0 -10
- data/spec/tls/server.csr +0 -16
- data/spec/tls/server_certificate.pem +0 -29
- data/spec/tls/server_key.pem +0 -51
- data/spec/unit/bunny_spec.rb +0 -15
- data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
- data/spec/unit/concurrent/condition_spec.rb +0 -82
- data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
- data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
- data/spec/unit/exchange_recovery_spec.rb +0 -39
- data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -1,85 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "A message that is proxied by multiple intermediate consumers" do
|
4
|
-
let(:c1) do
|
5
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:c2) do
|
11
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
12
|
-
c.start
|
13
|
-
c
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:c3) do
|
17
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
18
|
-
c.start
|
19
|
-
c
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:c4) do
|
23
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
24
|
-
c.start
|
25
|
-
c
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:c5) do
|
29
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
30
|
-
c.start
|
31
|
-
c
|
32
|
-
end
|
33
|
-
|
34
|
-
after :each do
|
35
|
-
[c1, c2, c3, c4, c5].each do |c|
|
36
|
-
c.close if c.open?
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# message flow is as follows:
|
41
|
-
#
|
42
|
-
# x => q4 => q3 => q2 => q1 => xs (results)
|
43
|
-
it "reaches its final destination" do
|
44
|
-
n = 10000
|
45
|
-
xs = []
|
46
|
-
|
47
|
-
ch1 = c1.create_channel
|
48
|
-
q1 = ch1.queue("", exclusive: true)
|
49
|
-
q1.subscribe do |_, _, payload|
|
50
|
-
xs << payload
|
51
|
-
end
|
52
|
-
|
53
|
-
ch2 = c2.create_channel
|
54
|
-
q2 = ch2.queue("", exclusive: true)
|
55
|
-
q2.subscribe do |_, _, payload|
|
56
|
-
q1.publish(payload)
|
57
|
-
end
|
58
|
-
|
59
|
-
ch3 = c3.create_channel
|
60
|
-
q3 = ch2.queue("", exclusive: true)
|
61
|
-
q3.subscribe do |_, _, payload|
|
62
|
-
q2.publish(payload)
|
63
|
-
end
|
64
|
-
|
65
|
-
ch4 = c4.create_channel
|
66
|
-
q4 = ch2.queue("", exclusive: true)
|
67
|
-
q4.subscribe do |_, _, payload|
|
68
|
-
q3.publish(payload)
|
69
|
-
end
|
70
|
-
|
71
|
-
ch5 = c5.create_channel
|
72
|
-
x = ch5.default_exchange
|
73
|
-
|
74
|
-
n.times do |i|
|
75
|
-
x.publish("msg #{i}", routing_key: q4.name)
|
76
|
-
end
|
77
|
-
|
78
|
-
t = n / 1000 * 3.0
|
79
|
-
puts "About to sleep for #{t} seconds..."
|
80
|
-
sleep(t)
|
81
|
-
|
82
|
-
expect(xs.size).to eq n
|
83
|
-
expect(xs.last).to eq "msg #{n - 1}"
|
84
|
-
end
|
85
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Queue, "#subscribe" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
connection.close if connection.open?
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
15
|
-
|
16
|
-
it "provides delivery handler access to message properties" do
|
17
|
-
@now = Time.now
|
18
|
-
metadata = {}
|
19
|
-
envelope = {}
|
20
|
-
|
21
|
-
t = Thread.new do
|
22
|
-
ch = connection.create_channel
|
23
|
-
q = ch.queue(queue_name, auto_delete: true, durable: false)
|
24
|
-
q.subscribe(exclusive: true, manual_ack: false) do |delivery_info, properties, payload|
|
25
|
-
metadata = properties
|
26
|
-
envelope = delivery_info
|
27
|
-
end
|
28
|
-
end
|
29
|
-
t.abort_on_exception = true
|
30
|
-
sleep 0.5
|
31
|
-
|
32
|
-
ch = connection.create_channel
|
33
|
-
x = ch.default_exchange
|
34
|
-
x.publish("hello",
|
35
|
-
routing_key: queue_name,
|
36
|
-
app_id: "bunny.example",
|
37
|
-
priority: 8,
|
38
|
-
type: "kinda.checkin",
|
39
|
-
# headers table keys can be anything
|
40
|
-
headers: {
|
41
|
-
coordinates: {
|
42
|
-
latitude: 59.35,
|
43
|
-
longitude: 18.066667
|
44
|
-
},
|
45
|
-
time: @now,
|
46
|
-
participants: 11,
|
47
|
-
venue: "Stockholm",
|
48
|
-
true_field: true,
|
49
|
-
false_field: false,
|
50
|
-
nil_field: nil,
|
51
|
-
ary_field: ["one", 2.0, 3, [{"abc" => 123}]]
|
52
|
-
},
|
53
|
-
timestamp: @now.to_i,
|
54
|
-
reply_to: "a.sender",
|
55
|
-
correlation_id: "r-1",
|
56
|
-
message_id: "m-1")
|
57
|
-
|
58
|
-
sleep 0.7
|
59
|
-
|
60
|
-
expect(metadata.content_type).to eq "application/octet-stream"
|
61
|
-
expect(metadata.priority).to eq 8
|
62
|
-
|
63
|
-
time = metadata.headers["time"]
|
64
|
-
expect(time.year).to eq @now.year
|
65
|
-
expect(time.month).to eq @now.month
|
66
|
-
expect(time.day).to eq @now.day
|
67
|
-
expect(time.hour).to eq @now.hour
|
68
|
-
expect(time.min).to eq @now.min
|
69
|
-
expect(time.sec).to eq @now.sec
|
70
|
-
|
71
|
-
expect(metadata.headers["coordinates"]["latitude"]).to eq 59.35
|
72
|
-
expect(metadata.headers["participants"]).to eq 11
|
73
|
-
expect(metadata.headers["venue"]).to eq "Stockholm"
|
74
|
-
expect(metadata.headers["true_field"]).to eq true
|
75
|
-
expect(metadata.headers["false_field"]).to eq false
|
76
|
-
expect(metadata.headers["nil_field"]).to be_nil
|
77
|
-
expect(metadata.headers["ary_field"]).to eq ["one", 2.0, 3, [{ "abc" => 123}]]
|
78
|
-
|
79
|
-
expect(metadata.timestamp).to eq Time.at(@now.to_i)
|
80
|
-
expect(metadata.type).to eq "kinda.checkin"
|
81
|
-
expect(metadata.reply_to).to eq "a.sender"
|
82
|
-
expect(metadata.correlation_id).to eq "r-1"
|
83
|
-
expect(metadata.message_id).to eq "m-1"
|
84
|
-
expect(metadata.app_id).to eq "bunny.example"
|
85
|
-
|
86
|
-
expect(envelope.consumer_tag).not_to be_nil
|
87
|
-
expect(envelope.consumer_tag).not_to be_empty
|
88
|
-
expect(envelope).not_to be_redelivered
|
89
|
-
expect(envelope.delivery_tag).to eq 1
|
90
|
-
expect(envelope.routing_key).to eq queue_name
|
91
|
-
expect(envelope.exchange).to eq ""
|
92
|
-
|
93
|
-
ch.close
|
94
|
-
end
|
95
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "amq.* exchanges" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
connection.close if connection.open?
|
12
|
-
end
|
13
|
-
|
14
|
-
it "are predeclared" do
|
15
|
-
ch = connection.create_channel
|
16
|
-
|
17
|
-
["amq.fanout", "amq.direct", "amq.topic", "amq.match", "amq.headers"].each do |e|
|
18
|
-
x = ch.exchange(e)
|
19
|
-
expect(x).to be_predeclared
|
20
|
-
end
|
21
|
-
|
22
|
-
ch.close
|
23
|
-
end
|
24
|
-
end
|
@@ -1,191 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel do
|
4
|
-
after :each do
|
5
|
-
connection.close if connection.open?
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:n) { 200 }
|
9
|
-
|
10
|
-
shared_examples "publish confirms" do
|
11
|
-
context "when publishing with confirms enabled" do
|
12
|
-
it "increments delivery index" do
|
13
|
-
ch = connection.create_channel
|
14
|
-
expect(ch).not_to be_using_publisher_confirmations
|
15
|
-
|
16
|
-
ch.confirm_select
|
17
|
-
expect(ch).to be_using_publisher_confirmations
|
18
|
-
|
19
|
-
q = ch.queue("", exclusive: true)
|
20
|
-
x = ch.default_exchange
|
21
|
-
|
22
|
-
n.times do
|
23
|
-
x.publish("xyzzy", routing_key: q.name)
|
24
|
-
end
|
25
|
-
|
26
|
-
expect(ch.next_publish_seq_no).to eq n + 1
|
27
|
-
expect(ch.wait_for_confirms).to eq true
|
28
|
-
sleep 0.25
|
29
|
-
|
30
|
-
expect(q.message_count).to eq n
|
31
|
-
q.purge
|
32
|
-
|
33
|
-
ch.close
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#wait_for_confirms" do
|
37
|
-
it "should not hang when all the publishes are confirmed" do
|
38
|
-
ch = connection.create_channel
|
39
|
-
expect(ch).not_to be_using_publisher_confirmations
|
40
|
-
|
41
|
-
ch.confirm_select
|
42
|
-
expect(ch).to be_using_publisher_confirmations
|
43
|
-
|
44
|
-
q = ch.queue("", exclusive: true)
|
45
|
-
x = ch.default_exchange
|
46
|
-
|
47
|
-
n.times do
|
48
|
-
x.publish("xyzzy", routing_key: q.name)
|
49
|
-
end
|
50
|
-
|
51
|
-
expect(ch.next_publish_seq_no).to eq n + 1
|
52
|
-
expect(ch.wait_for_confirms).to eq true
|
53
|
-
|
54
|
-
sleep 0.25
|
55
|
-
|
56
|
-
expect {
|
57
|
-
Bunny::Timeout.timeout(2) do
|
58
|
-
expect(ch.wait_for_confirms).to eq true
|
59
|
-
end
|
60
|
-
}.not_to raise_error
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
it "raises an error when called on a closed channel" do
|
65
|
-
ch = connection.create_channel
|
66
|
-
|
67
|
-
ch.confirm_select
|
68
|
-
|
69
|
-
ch.close
|
70
|
-
|
71
|
-
expect {
|
72
|
-
ch.wait_for_confirms
|
73
|
-
}.to raise_error(Bunny::ChannelAlreadyClosed)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when some of the messages get nacked" do
|
78
|
-
it "puts the nacks in the nacked_set" do
|
79
|
-
ch = connection.create_channel
|
80
|
-
expect(ch).not_to be_using_publisher_confirmations
|
81
|
-
|
82
|
-
ch.confirm_select
|
83
|
-
expect(ch).to be_using_publisher_confirmations
|
84
|
-
|
85
|
-
q = ch.queue("", exclusive: true)
|
86
|
-
x = ch.default_exchange
|
87
|
-
|
88
|
-
n.times do
|
89
|
-
x.publish("xyzzy", routing_key: q.name)
|
90
|
-
end
|
91
|
-
|
92
|
-
#be sneaky to simulate a nack
|
93
|
-
nacked_tag = nil
|
94
|
-
ch.instance_variable_get(:@unconfirmed_set_mutex).synchronize do
|
95
|
-
expect(ch.unconfirmed_set).to_not be_empty
|
96
|
-
nacked_tag = ch.unconfirmed_set.reduce(ch.next_publish_seq_no - 1) { |lowest, i| i < lowest ? i : lowest }
|
97
|
-
ch.handle_ack_or_nack(nacked_tag, false, true)
|
98
|
-
end
|
99
|
-
|
100
|
-
expect(ch.nacked_set).not_to be_empty
|
101
|
-
expect(ch.nacked_set).to include(nacked_tag)
|
102
|
-
|
103
|
-
expect(ch.next_publish_seq_no).to eq n + 1
|
104
|
-
expect(ch.wait_for_confirms).to eq false
|
105
|
-
|
106
|
-
expect(ch.nacked_set).not_to be_empty
|
107
|
-
expect(ch.nacked_set).to include(nacked_tag)
|
108
|
-
|
109
|
-
sleep 0.25
|
110
|
-
expect(q.message_count).to eq n
|
111
|
-
q.purge
|
112
|
-
|
113
|
-
ch.close
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "with a multi-threaded connection" do
|
120
|
-
let(:connection) do
|
121
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed", continuation_timeout: 10000)
|
122
|
-
c.start
|
123
|
-
c
|
124
|
-
end
|
125
|
-
|
126
|
-
include_examples "publish confirms"
|
127
|
-
|
128
|
-
it "returns only when all confirmations for publishes are received" do
|
129
|
-
ch = connection.create_channel
|
130
|
-
|
131
|
-
operations_log = []
|
132
|
-
operations_log_mutex = Mutex.new
|
133
|
-
acks_received = Queue.new
|
134
|
-
|
135
|
-
log_acks = proc do |tag, _, is_nack|
|
136
|
-
operations_log_mutex.synchronize do
|
137
|
-
operation = "#{'n' if is_nack}ack_#{tag}"
|
138
|
-
operations_log << operation unless operations_log.include?(operation)
|
139
|
-
end
|
140
|
-
acks_received << true
|
141
|
-
end
|
142
|
-
|
143
|
-
ch.confirm_select(log_acks)
|
144
|
-
|
145
|
-
x = ch.default_exchange
|
146
|
-
q = ch.temporary_queue
|
147
|
-
|
148
|
-
x.publish('msg', routing_key: q.name)
|
149
|
-
|
150
|
-
# wait for the confirmation to arrive
|
151
|
-
acks_received.pop
|
152
|
-
|
153
|
-
# artificially simulate a slower ack. the test should work properly even
|
154
|
-
# without this patch, but it's here just to be sure we catch it.
|
155
|
-
def (x.channel).handle_ack_or_nack(delivery_tag_before_offset, multiple, nack)
|
156
|
-
sleep 0.1
|
157
|
-
super
|
158
|
-
end
|
159
|
-
|
160
|
-
x.publish('msg', routing_key: q.name)
|
161
|
-
x.publish('msg', routing_key: q.name)
|
162
|
-
|
163
|
-
if x.wait_for_confirms
|
164
|
-
operations_log_mutex.synchronize do
|
165
|
-
operations_log << 'all_confirmed'
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# wait for all the confirmations to arrive
|
170
|
-
acks_received.pop
|
171
|
-
acks_received.pop
|
172
|
-
|
173
|
-
expect(operations_log).to eq([
|
174
|
-
'ack_1',
|
175
|
-
'ack_2',
|
176
|
-
'ack_3',
|
177
|
-
'all_confirmed',
|
178
|
-
])
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
context "with a single-threaded connection" do
|
183
|
-
let(:connection) do
|
184
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed", continuation_timeout: 10000, threaded: false)
|
185
|
-
c.start
|
186
|
-
c
|
187
|
-
end
|
188
|
-
|
189
|
-
include_examples "publish confirms"
|
190
|
-
end
|
191
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
unless ENV["CI"]
|
5
|
-
describe "Message framing implementation" do
|
6
|
-
let(:connection) do
|
7
|
-
c = Bunny.new(username: "bunny_gem",
|
8
|
-
password: "bunny_password",
|
9
|
-
vhost: "bunny_testbed",
|
10
|
-
port: ENV.fetch("RABBITMQ_PORT", 5672))
|
11
|
-
c.start
|
12
|
-
c
|
13
|
-
end
|
14
|
-
|
15
|
-
after :each do
|
16
|
-
connection.close if connection.open?
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
context "with payload exceeding 128 Kb (max frame size)" do
|
21
|
-
it "successfully frames the message" do
|
22
|
-
ch = connection.create_channel
|
23
|
-
|
24
|
-
q = ch.queue("", exclusive: true)
|
25
|
-
x = ch.default_exchange
|
26
|
-
|
27
|
-
as = ("a" * (1024 * 1024 * 4 + 28237777))
|
28
|
-
x.publish(as, routing_key: q.name, persistent: true)
|
29
|
-
|
30
|
-
sleep(1)
|
31
|
-
expect(q.message_count).to eq 1
|
32
|
-
|
33
|
-
_, _, payload = q.pop
|
34
|
-
expect(payload.bytesize).to eq as.bytesize
|
35
|
-
|
36
|
-
ch.close
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
context "with payload of several MBs of non-ASCII characters" do
|
42
|
-
it "successfully frames the message" do
|
43
|
-
ch = connection.create_channel
|
44
|
-
|
45
|
-
q = ch.queue("", exclusive: true)
|
46
|
-
x = ch.default_exchange
|
47
|
-
|
48
|
-
as = "кириллца, йо" * (1024 * 1024)
|
49
|
-
x.publish(as, routing_key: q.name, persistent: true)
|
50
|
-
|
51
|
-
sleep(1)
|
52
|
-
expect(q.message_count).to eq 1
|
53
|
-
|
54
|
-
_, _, payload = q.pop
|
55
|
-
expect(payload.bytesize).to eq as.bytesize
|
56
|
-
|
57
|
-
ch.close
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
context "with empty message body" do
|
64
|
-
it "successfully publishes the message" do
|
65
|
-
ch = connection.create_channel
|
66
|
-
|
67
|
-
q = ch.queue("", exclusive: true)
|
68
|
-
x = ch.default_exchange
|
69
|
-
|
70
|
-
x.publish("", routing_key: q.name, persistent: false, mandatory: true)
|
71
|
-
|
72
|
-
sleep(0.5)
|
73
|
-
expect(q.message_count).to eq 1
|
74
|
-
|
75
|
-
envelope, headers, payload = q.pop
|
76
|
-
|
77
|
-
expect(payload).to eq ""
|
78
|
-
|
79
|
-
expect(headers[:content_type]).to eq "application/octet-stream"
|
80
|
-
expect(headers[:delivery_mode]).to eq 1
|
81
|
-
expect(headers[:priority]).to eq 0
|
82
|
-
|
83
|
-
ch.close
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "A client-named", Bunny::Queue do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
it "can be bound to a pre-declared exchange" do
|
11
|
-
ch = connection.create_channel
|
12
|
-
q = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
|
13
|
-
expect(q).not_to be_server_named
|
14
|
-
|
15
|
-
expect(q.bind("amq.fanout")).to eq q
|
16
|
-
|
17
|
-
ch.close
|
18
|
-
end
|
19
|
-
|
20
|
-
it "can be unbound from a pre-declared exchange" do
|
21
|
-
ch = connection.create_channel
|
22
|
-
q = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
|
23
|
-
expect(q).not_to be_server_named
|
24
|
-
|
25
|
-
q.bind("amq.fanout")
|
26
|
-
expect(q.unbind("amq.fanout")).to eq q
|
27
|
-
|
28
|
-
ch.close
|
29
|
-
end
|
30
|
-
|
31
|
-
it "can be bound to a custom exchange" do
|
32
|
-
ch = connection.create_channel
|
33
|
-
q = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
|
34
|
-
|
35
|
-
x = ch.fanout("bunny.tests.exchanges.fanout#{rand}")
|
36
|
-
expect(q.bind(x)).to eq q
|
37
|
-
|
38
|
-
x.delete
|
39
|
-
ch.close
|
40
|
-
end
|
41
|
-
|
42
|
-
it "can be unbound from a custom exchange" do
|
43
|
-
ch = connection.create_channel
|
44
|
-
q = ch.queue("bunny.tests.queues.client-named#{rand}", exclusive: true)
|
45
|
-
expect(q).not_to be_server_named
|
46
|
-
|
47
|
-
x = ch.fanout("bunny.tests.fanout", auto_delete: true, durable: false)
|
48
|
-
|
49
|
-
q.bind(x)
|
50
|
-
expect(q.unbind(x)).to eq q
|
51
|
-
|
52
|
-
ch.close
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
describe "A server-named", Bunny::Queue do
|
59
|
-
let(:connection) do
|
60
|
-
c = Bunny.new
|
61
|
-
c.start
|
62
|
-
c
|
63
|
-
end
|
64
|
-
|
65
|
-
it "can be bound to a pre-declared exchange" do
|
66
|
-
ch = connection.create_channel
|
67
|
-
q = ch.queue("", exclusive: true)
|
68
|
-
expect(q).to be_server_named
|
69
|
-
|
70
|
-
expect(q.bind("amq.fanout")).to eq q
|
71
|
-
|
72
|
-
ch.close
|
73
|
-
end
|
74
|
-
|
75
|
-
it "can be unbound from a pre-declared exchange" do
|
76
|
-
ch = connection.create_channel
|
77
|
-
q = ch.queue("", exclusive: true)
|
78
|
-
expect(q).to be_server_named
|
79
|
-
|
80
|
-
q.bind("amq.fanout")
|
81
|
-
expect(q.unbind("amq.fanout")).to eq q
|
82
|
-
|
83
|
-
ch.close
|
84
|
-
end
|
85
|
-
|
86
|
-
it "can be bound to a custom exchange" do
|
87
|
-
ch = connection.create_channel
|
88
|
-
q = ch.queue("", exclusive: true)
|
89
|
-
|
90
|
-
x = ch.fanout("bunny.tests.exchanges.fanout#{rand}")
|
91
|
-
expect(q.bind(x)).to eq q
|
92
|
-
|
93
|
-
x.delete
|
94
|
-
ch.close
|
95
|
-
end
|
96
|
-
|
97
|
-
it "can be bound from a custom exchange" do
|
98
|
-
ch = connection.create_channel
|
99
|
-
q = ch.queue("", exclusive: true)
|
100
|
-
|
101
|
-
name = "bunny.tests.exchanges.fanout#{rand}"
|
102
|
-
x = ch.fanout(name)
|
103
|
-
q.bind(x)
|
104
|
-
expect(q.unbind(name)).to eq q
|
105
|
-
|
106
|
-
x.delete
|
107
|
-
ch.close
|
108
|
-
end
|
109
|
-
end
|