bunny 1.0.7 → 2.24.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/README.md +92 -87
- data/lib/amq/protocol/extensions.rb +2 -0
- data/lib/bunny/authentication/credentials_encoder.rb +2 -0
- data/lib/bunny/authentication/external_mechanism_encoder.rb +2 -0
- data/lib/bunny/authentication/plain_mechanism_encoder.rb +2 -0
- data/lib/bunny/channel.rb +485 -186
- data/lib/bunny/channel_id_allocator.rb +8 -4
- data/lib/bunny/concurrent/atomic_fixnum.rb +2 -0
- data/lib/bunny/concurrent/condition.rb +2 -0
- data/lib/bunny/concurrent/continuation_queue.rb +37 -13
- data/lib/bunny/concurrent/synchronized_sorted_set.rb +2 -0
- data/lib/bunny/consumer.rb +20 -13
- data/lib/bunny/consumer_tag_generator.rb +6 -2
- data/lib/bunny/consumer_work_pool.rb +37 -7
- data/lib/bunny/cruby/socket.rb +51 -22
- data/lib/bunny/cruby/ssl_socket.rb +68 -5
- data/lib/bunny/delivery_info.rb +3 -1
- data/lib/bunny/exceptions.rb +27 -4
- data/lib/bunny/exchange.rb +35 -29
- data/lib/bunny/framing.rb +2 -0
- data/lib/bunny/get_response.rb +85 -0
- data/lib/bunny/heartbeat_sender.rb +9 -6
- data/lib/bunny/message_properties.rb +2 -0
- data/lib/bunny/queue.rb +89 -41
- data/lib/bunny/reader_loop.rb +72 -28
- data/lib/bunny/return_info.rb +2 -0
- data/lib/bunny/session.rb +621 -225
- data/lib/bunny/socket.rb +7 -12
- data/lib/bunny/ssl_socket.rb +7 -12
- data/lib/bunny/test_kit.rb +15 -0
- data/lib/bunny/timeout.rb +3 -12
- data/lib/bunny/timestamp.rb +24 -0
- data/lib/bunny/transport.rb +223 -98
- data/lib/bunny/version.rb +2 -1
- data/lib/bunny/versioned_delivery_tag.rb +2 -0
- data/lib/bunny.rb +54 -8
- metadata +38 -224
- data/.gitignore +0 -22
- data/.rspec +0 -3
- data/.ruby-version +0 -1
- data/.travis.yml +0 -23
- data/.yardopts +0 -8
- data/ChangeLog.md +0 -1092
- data/Gemfile +0 -54
- data/LICENSE +0 -21
- 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.sh +0 -31
- data/bunny.gemspec +0 -40
- 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_server_named_queues.rb +0 -35
- data/examples/connection/channel_level_exception.rb +0 -35
- 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/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 -28
- 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 -20
- data/examples/guides/getting_started/weathr.rb +0 -47
- data/examples/guides/queues/one_off_consumer.rb +0 -23
- data/examples/guides/queues/redeliveries.rb +0 -79
- data/lib/bunny/compatibility.rb +0 -24
- data/lib/bunny/concurrent/linked_continuation_queue.rb +0 -61
- data/lib/bunny/jruby/socket.rb +0 -40
- data/lib/bunny/jruby/ssl_socket.rb +0 -53
- data/lib/bunny/system_timer.rb +0 -20
- data/profiling/basic_publish/with_4K_messages.rb +0 -33
- data/repl +0 -3
- data/spec/compatibility/queue_declare_spec.rb +0 -44
- data/spec/compatibility/queue_declare_with_default_channel_spec.rb +0 -33
- data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -71
- data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -76
- data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -225
- 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 -48
- data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -79
- data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -89
- data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -29
- data/spec/higher_level_api/integration/basic_recover_spec.rb +0 -18
- data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -74
- 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_flow_spec.rb +0 -21
- data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
- data/spec/higher_level_api/integration/confirm_select_spec.rb +0 -19
- data/spec/higher_level_api/integration/connection_spec.rb +0 -400
- data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -26
- data/spec/higher_level_api/integration/consistent_hash_exchange_spec.rb +0 -50
- data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
- data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -52
- data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
- data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -204
- 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 -31
- 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 -77
- data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -65
- data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
- data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -190
- 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 -127
- 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 -44
- data/spec/issues/issue78_spec.rb +0 -75
- data/spec/issues/issue83_spec.rb +0 -31
- data/spec/issues/issue97_attachment.json +0 -1
- data/spec/issues/issue97_spec.rb +0 -176
- data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -69
- data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -100
- data/spec/spec_helper.rb +0 -64
- data/spec/stress/channel_open_stress_spec.rb +0 -51
- data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
- data/spec/stress/concurrent_consumers_stress_spec.rb +0 -69
- data/spec/stress/concurrent_publishers_stress_spec.rb +0 -57
- data/spec/stress/connection_open_close_spec.rb +0 -40
- 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/client_key.pem +0 -27
- data/spec/tls/server_cert.pem +0 -18
- data/spec/tls/server_key.pem +0 -27
- 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/system_timer_spec.rb +0 -10
- data/spec/unit/version_delivery_tag_spec.rb +0 -28
data/spec/issues/issue97_spec.rb
DELETED
@@ -1,176 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Message framing implementation" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(:user => "bunny_gem",
|
6
|
-
:password => "bunny_password",
|
7
|
-
:vhost => "bunny_testbed",
|
8
|
-
:port => ENV.fetch("RABBITMQ_PORT", 5672))
|
9
|
-
c.start
|
10
|
-
c
|
11
|
-
end
|
12
|
-
|
13
|
-
after :all do
|
14
|
-
connection.close if connection.open?
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
unless ENV["CI"]
|
19
|
-
context "with payload ~ 248K in size including non-ASCII characters" do
|
20
|
-
it "successfully frames the message" do
|
21
|
-
ch = connection.create_channel
|
22
|
-
|
23
|
-
q = ch.queue("", :exclusive => true)
|
24
|
-
x = ch.default_exchange
|
25
|
-
|
26
|
-
body = IO.read("spec/issues/issue97_attachment.json")
|
27
|
-
x.publish(body, :routing_key => q.name, :persistent => true)
|
28
|
-
|
29
|
-
sleep(1)
|
30
|
-
q.message_count.should == 1
|
31
|
-
|
32
|
-
q.purge
|
33
|
-
ch.close
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
context "with payload of several MBs in size" do
|
40
|
-
it "successfully frames the message" do
|
41
|
-
ch = connection.create_channel
|
42
|
-
|
43
|
-
q = ch.queue("", :exclusive => true)
|
44
|
-
x = ch.default_exchange
|
45
|
-
|
46
|
-
as = ("a" * (1024 * 1024 * 4 + 2823777))
|
47
|
-
x.publish(as, :routing_key => q.name, :persistent => true)
|
48
|
-
|
49
|
-
sleep(1)
|
50
|
-
q.message_count.should == 1
|
51
|
-
|
52
|
-
_, _, payload = q.pop
|
53
|
-
payload.bytesize.should == as.bytesize
|
54
|
-
|
55
|
-
ch.close
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
context "with empty message body" do
|
62
|
-
it "successfully publishes the message" do
|
63
|
-
ch = connection.create_channel
|
64
|
-
|
65
|
-
q = ch.queue("", :exclusive => true)
|
66
|
-
x = ch.default_exchange
|
67
|
-
|
68
|
-
x.publish("", :routing_key => q.name, :persistent => true)
|
69
|
-
|
70
|
-
sleep(1)
|
71
|
-
q.message_count.should == 1
|
72
|
-
|
73
|
-
envelope, headers, payload = q.pop
|
74
|
-
|
75
|
-
payload.should == ""
|
76
|
-
|
77
|
-
headers[:content_type].should == "application/octet-stream"
|
78
|
-
headers[:delivery_mode].should == 2
|
79
|
-
headers[:priority].should == 0
|
80
|
-
|
81
|
-
ch.close
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
context "with payload being 2 bytes less than 128K bytes in size" do
|
87
|
-
it "successfully frames the message" do
|
88
|
-
ch = connection.create_channel
|
89
|
-
|
90
|
-
q = ch.queue("", :exclusive => true)
|
91
|
-
x = ch.default_exchange
|
92
|
-
|
93
|
-
as = "a" * (1024 * 128 - 2)
|
94
|
-
x.publish(as, :routing_key => q.name, :persistent => true)
|
95
|
-
|
96
|
-
sleep(1)
|
97
|
-
q.message_count.should == 1
|
98
|
-
|
99
|
-
q.purge
|
100
|
-
ch.close
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "with payload being 1 byte less than 128K bytes in size" do
|
105
|
-
it "successfully frames the message" do
|
106
|
-
ch = connection.create_channel
|
107
|
-
|
108
|
-
q = ch.queue("", :exclusive => true)
|
109
|
-
x = ch.default_exchange
|
110
|
-
|
111
|
-
as = "a" * (1024 * 128 - 1)
|
112
|
-
x.publish(as, :routing_key => q.name, :persistent => true)
|
113
|
-
|
114
|
-
sleep(1)
|
115
|
-
q.message_count.should == 1
|
116
|
-
|
117
|
-
q.purge
|
118
|
-
ch.close
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "with payload being exactly 128K bytes in size" do
|
123
|
-
it "successfully frames the message" do
|
124
|
-
ch = connection.create_channel
|
125
|
-
|
126
|
-
q = ch.queue("", :exclusive => true)
|
127
|
-
x = ch.default_exchange
|
128
|
-
|
129
|
-
as = "a" * (1024 * 128)
|
130
|
-
x.publish(as, :routing_key => q.name, :persistent => true)
|
131
|
-
|
132
|
-
sleep(1)
|
133
|
-
q.message_count.should == 1
|
134
|
-
|
135
|
-
q.purge
|
136
|
-
ch.close
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
context "with payload being 1 byte greater than 128K bytes in size" do
|
142
|
-
it "successfully frames the message" do
|
143
|
-
ch = connection.create_channel
|
144
|
-
|
145
|
-
q = ch.queue("", :exclusive => true)
|
146
|
-
x = ch.default_exchange
|
147
|
-
|
148
|
-
as = "a" * (1024 * 128 + 1)
|
149
|
-
x.publish(as, :routing_key => q.name, :persistent => true)
|
150
|
-
|
151
|
-
sleep(1)
|
152
|
-
q.message_count.should == 1
|
153
|
-
|
154
|
-
q.purge
|
155
|
-
ch.close
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context "with payload being 2 bytes greater than 128K bytes in size" do
|
160
|
-
it "successfully frames the message" do
|
161
|
-
ch = connection.create_channel
|
162
|
-
|
163
|
-
q = ch.queue("", :exclusive => true)
|
164
|
-
x = ch.default_exchange
|
165
|
-
|
166
|
-
as = "a" * (1024 * 128 + 2)
|
167
|
-
x.publish(as, :routing_key => q.name, :persistent => true)
|
168
|
-
|
169
|
-
sleep(1)
|
170
|
-
q.message_count.should == 1
|
171
|
-
|
172
|
-
q.purge
|
173
|
-
ch.close
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#basic_cancel" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
after :all do
|
11
|
-
connection.close if connection.open?
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:queue_name) { "bunny.queues.#{rand}" }
|
15
|
-
|
16
|
-
it "returns basic.cancel-ok" do
|
17
|
-
ch = connection.create_channel
|
18
|
-
q = ch.queue("", :exclusive => true)
|
19
|
-
|
20
|
-
consume_ok = ch.basic_consume(q, "")
|
21
|
-
cancel_ok = ch.basic_cancel(consume_ok.consumer_tag)
|
22
|
-
|
23
|
-
cancel_ok.should be_instance_of(AMQ::Protocol::Basic::CancelOk)
|
24
|
-
cancel_ok.consumer_tag.should == consume_ok.consumer_tag
|
25
|
-
|
26
|
-
ch.close
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when the given consumer tag is valid" do
|
30
|
-
let(:queue_name) { "bunny.basic.cancel.queue#{rand}" }
|
31
|
-
|
32
|
-
it "cancels the consumer" do
|
33
|
-
delivered_data = []
|
34
|
-
|
35
|
-
t = Thread.new do
|
36
|
-
ch = connection.create_channel
|
37
|
-
q = ch.queue(queue_name, :auto_delete => true, :durable => false)
|
38
|
-
consume_ok = ch.basic_consume(q, "", true, false) do |_, _, payload|
|
39
|
-
delivered_data << payload
|
40
|
-
end
|
41
|
-
|
42
|
-
consume_ok.consumer_tag.should_not be_nil
|
43
|
-
cancel_ok = ch.basic_cancel(consume_ok.consumer_tag)
|
44
|
-
cancel_ok.consumer_tag.should == consume_ok.consumer_tag
|
45
|
-
|
46
|
-
ch.close
|
47
|
-
end
|
48
|
-
t.abort_on_exception = true
|
49
|
-
sleep 0.5
|
50
|
-
|
51
|
-
ch = connection.create_channel
|
52
|
-
ch.default_exchange.publish("", :routing_key => queue_name)
|
53
|
-
|
54
|
-
sleep 0.7
|
55
|
-
delivered_data.should be_empty
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when the given consumer tag is invalid (was never registered)" do
|
60
|
-
it "DOES NOT cause a channel error" do
|
61
|
-
ch = connection.create_channel
|
62
|
-
|
63
|
-
# RabbitMQ 3.1 does not raise an exception w/ unknown consumer tag. MK.
|
64
|
-
ch.basic_cancel("878798s7df89#{rand}#{Time.now.to_i}")
|
65
|
-
|
66
|
-
ch.close
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#basic_consume" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
after :all do
|
11
|
-
connection.close if connection.open?
|
12
|
-
end
|
13
|
-
|
14
|
-
it "returns basic.consume-ok when it is received" do
|
15
|
-
ch = connection.create_channel
|
16
|
-
q = ch.queue("", :exclusive => true)
|
17
|
-
|
18
|
-
consume_ok = ch.basic_consume(q)
|
19
|
-
consume_ok.should be_instance_of(AMQ::Protocol::Basic::ConsumeOk)
|
20
|
-
consume_ok.consumer_tag.should_not be_nil
|
21
|
-
|
22
|
-
ch.close
|
23
|
-
end
|
24
|
-
|
25
|
-
it "carries server-generated consumer tag with basic.consume-ok" do
|
26
|
-
ch = connection.create_channel
|
27
|
-
q = ch.queue("", :exclusive => true)
|
28
|
-
|
29
|
-
consume_ok = ch.basic_consume(q, "")
|
30
|
-
consume_ok.consumer_tag.should =~ /amq\.ctag.*/
|
31
|
-
|
32
|
-
ch.close
|
33
|
-
end
|
34
|
-
|
35
|
-
context "with automatic acknowledgement mode" do
|
36
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
37
|
-
|
38
|
-
it "causes messages to be automatically removed from the queue after delivery" do
|
39
|
-
delivered_keys = []
|
40
|
-
delivered_data = []
|
41
|
-
|
42
|
-
t = Thread.new do
|
43
|
-
ch = connection.create_channel
|
44
|
-
q = ch.queue(queue_name, :auto_delete => true, :durable => false)
|
45
|
-
ch.basic_consume(q, "", true, false) do |delivery_info, properties, payload|
|
46
|
-
delivered_keys << delivery_info.routing_key
|
47
|
-
delivered_data << payload
|
48
|
-
end
|
49
|
-
end
|
50
|
-
t.abort_on_exception = true
|
51
|
-
sleep 0.5
|
52
|
-
|
53
|
-
ch = connection.create_channel
|
54
|
-
x = ch.default_exchange
|
55
|
-
x.publish("hello", :routing_key => queue_name)
|
56
|
-
|
57
|
-
sleep 0.7
|
58
|
-
delivered_keys.should include(queue_name)
|
59
|
-
delivered_data.should include("hello")
|
60
|
-
|
61
|
-
ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
|
62
|
-
|
63
|
-
ch.close
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "with manual acknowledgement mode" do
|
68
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
69
|
-
|
70
|
-
it "waits for an explicit acknowledgement" do
|
71
|
-
delivered_keys = []
|
72
|
-
delivered_data = []
|
73
|
-
|
74
|
-
t = Thread.new do
|
75
|
-
ch = connection.create_channel
|
76
|
-
q = ch.queue(queue_name, :auto_delete => true, :durable => false)
|
77
|
-
ch.basic_consume(q, "", false, false) do |delivery_info, properties, payload|
|
78
|
-
delivered_keys << delivery_info.routing_key
|
79
|
-
delivered_data << payload
|
80
|
-
|
81
|
-
ch.close
|
82
|
-
end
|
83
|
-
end
|
84
|
-
t.abort_on_exception = true
|
85
|
-
sleep 0.5
|
86
|
-
|
87
|
-
ch = connection.create_channel
|
88
|
-
x = ch.default_exchange
|
89
|
-
x.publish("hello", :routing_key => queue_name)
|
90
|
-
|
91
|
-
sleep 0.7
|
92
|
-
delivered_keys.should include(queue_name)
|
93
|
-
delivered_data.should include("hello")
|
94
|
-
|
95
|
-
ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
|
96
|
-
|
97
|
-
ch.close
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8; mode: ruby -*-
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
4
|
-
|
5
|
-
require 'bundler'
|
6
|
-
Bundler.setup(:default, :test)
|
7
|
-
|
8
|
-
|
9
|
-
require "effin_utf8"
|
10
|
-
require "bunny"
|
11
|
-
|
12
|
-
|
13
|
-
require "amq/protocol/version"
|
14
|
-
puts "Using Ruby #{RUBY_VERSION}, amq-protocol #{AMQ::Protocol::VERSION}"
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
# Ruby version-specific
|
20
|
-
#
|
21
|
-
|
22
|
-
case RUBY_VERSION
|
23
|
-
when "1.8.7" then
|
24
|
-
class Array
|
25
|
-
alias sample choice
|
26
|
-
end
|
27
|
-
when "1.8.6" then
|
28
|
-
raise "Ruby 1.8.6 is not supported. Sorry, pal. Time to move on beyond One True Ruby. Yes, time flies by."
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
module RabbitMQ
|
34
|
-
module Control
|
35
|
-
def rabbitmq_pid
|
36
|
-
$1.to_i if `rabbitmqctl status` =~ /\{pid,(\d+)\}/
|
37
|
-
end
|
38
|
-
|
39
|
-
def start_rabbitmq(delay = 1.0)
|
40
|
-
# this is Homebrew-specific :(
|
41
|
-
`rabbitmq-server > /dev/null 2>&1 &`; sleep(delay)
|
42
|
-
end
|
43
|
-
|
44
|
-
def stop_rabbitmq(pid = rabbitmq_pid, delay = 1.0)
|
45
|
-
`rabbitmqctl stop`; sleep(delay)
|
46
|
-
end
|
47
|
-
|
48
|
-
def kill_rabbitmq(pid = rabbitmq_pid, delay = 1.0)
|
49
|
-
# tango is down, tango is down!
|
50
|
-
Process.kill("KILL", pid); sleep(delay)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
module PlatformDetection
|
57
|
-
def mri?
|
58
|
-
!defined?(RUBY_ENGINE) || (defined?(RUBY_ENGINE) && ("ruby" == RUBY_ENGINE))
|
59
|
-
end
|
60
|
-
|
61
|
-
def rubinius?
|
62
|
-
defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'rbx')
|
63
|
-
end
|
64
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
unless ENV["CI"]
|
4
|
-
describe "Rapidly opening and closing lots of channels" do
|
5
|
-
let(:connection) do
|
6
|
-
c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatic_recovery => false)
|
7
|
-
c.start
|
8
|
-
c
|
9
|
-
end
|
10
|
-
|
11
|
-
after :all do
|
12
|
-
connection.close
|
13
|
-
end
|
14
|
-
|
15
|
-
context "in a single-threaded scenario" do
|
16
|
-
let(:n) { 500 }
|
17
|
-
|
18
|
-
it "works correctly" do
|
19
|
-
xs = Array.new(n) { connection.create_channel }
|
20
|
-
puts "Opened #{n} channels"
|
21
|
-
|
22
|
-
xs.size.should == n
|
23
|
-
xs.each do |ch|
|
24
|
-
ch.close
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "in a multi-threaded scenario" do
|
30
|
-
# actually, on MRI values greater than ~100 will eventually cause write
|
31
|
-
# operations to fail with a timeout (1 second is not enough)
|
32
|
-
# which will cause recovery to re-acquire @channel_mutex in Session.
|
33
|
-
# Because Ruby's mutexes are not re-entrant, it will raise a ThreadError.
|
34
|
-
#
|
35
|
-
# But this already demonstrates that within these platform constraints,
|
36
|
-
# Bunny is safe to use in such scenarios.
|
37
|
-
let(:n) { 20 }
|
38
|
-
|
39
|
-
it "works correctly" do
|
40
|
-
n.times do
|
41
|
-
t = Thread.new do
|
42
|
-
ch = connection.create_channel
|
43
|
-
|
44
|
-
ch.close
|
45
|
-
end
|
46
|
-
t.abort_on_exception = true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
unless ENV["CI"]
|
4
|
-
describe "Rapidly opening and closing lots of channels on a non-threaded connection" do
|
5
|
-
let(:connection) do
|
6
|
-
c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatic_recovery => false, :threaded => false)
|
7
|
-
c.start
|
8
|
-
c
|
9
|
-
end
|
10
|
-
|
11
|
-
after :all do
|
12
|
-
connection.close
|
13
|
-
end
|
14
|
-
|
15
|
-
context "in a single-threaded scenario" do
|
16
|
-
let(:n) { 500 }
|
17
|
-
|
18
|
-
it "works correctly" do
|
19
|
-
xs = Array.new(n) { connection.create_channel }
|
20
|
-
|
21
|
-
xs.size.should == n
|
22
|
-
xs.each do |ch|
|
23
|
-
ch.close
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
unless ENV["CI"]
|
5
|
-
describe "Concurrent consumers sharing a connection" do
|
6
|
-
let(:connection) do
|
7
|
-
c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed",
|
8
|
-
:automatic_recovery => false, :continuation_timeout => 6000)
|
9
|
-
c.start
|
10
|
-
c
|
11
|
-
end
|
12
|
-
|
13
|
-
after :all do
|
14
|
-
connection.close
|
15
|
-
end
|
16
|
-
|
17
|
-
def any_not_drained?(qs)
|
18
|
-
qs.any? { |q| !q.message_count.zero? }
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when publishing thousands of messages over 128K in size" do
|
22
|
-
let(:colors) { ["red", "blue", "white"] }
|
23
|
-
|
24
|
-
let(:n) { 32 }
|
25
|
-
let(:m) { 1000 }
|
26
|
-
|
27
|
-
it "successfully drain all queues" do
|
28
|
-
ch = connection.create_channel
|
29
|
-
body = "абвг"
|
30
|
-
x = ch.topic("bunny.stress.concurrent.consumers.topic", :durable => true)
|
31
|
-
|
32
|
-
chs = {}
|
33
|
-
n.times do |i|
|
34
|
-
chs[i] = connection.create_channel
|
35
|
-
end
|
36
|
-
qs = []
|
37
|
-
|
38
|
-
n.times do |i|
|
39
|
-
t = Thread.new do
|
40
|
-
cht = chs[i]
|
41
|
-
|
42
|
-
q = cht.queue("", :exclusive => true)
|
43
|
-
q.bind(x.name, :routing_key => colors.sample).subscribe do |delivery_info, meta, payload|
|
44
|
-
# no-op
|
45
|
-
end
|
46
|
-
qs << q
|
47
|
-
end
|
48
|
-
t.abort_on_exception = true
|
49
|
-
end
|
50
|
-
|
51
|
-
sleep 1.0
|
52
|
-
|
53
|
-
5.times do |i|
|
54
|
-
m.times do
|
55
|
-
x.publish(body, :routing_key => colors.sample)
|
56
|
-
end
|
57
|
-
puts "Published #{(i + 1) * m} messages..."
|
58
|
-
end
|
59
|
-
|
60
|
-
while any_not_drained?(qs)
|
61
|
-
sleep 1.0
|
62
|
-
end
|
63
|
-
puts "Drained all the queues..."
|
64
|
-
|
65
|
-
ch.close
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
unless ENV["CI"]
|
5
|
-
describe "Concurrent publishers sharing a connection" do
|
6
|
-
let(:connection) do
|
7
|
-
c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatically_recover => false, :continuation_timeout => 20.0)
|
8
|
-
c.start
|
9
|
-
c
|
10
|
-
end
|
11
|
-
|
12
|
-
after :all do
|
13
|
-
connection.close
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:concurrency) { 24 }
|
17
|
-
let(:rate) { 5_000 }
|
18
|
-
|
19
|
-
it "successfully finish publishing" do
|
20
|
-
ch = connection.create_channel
|
21
|
-
|
22
|
-
q = ch.queue("", :exclusive => true)
|
23
|
-
body = "сообщение"
|
24
|
-
|
25
|
-
# let the queue name be sent back by RabbitMQ
|
26
|
-
sleep 0.25
|
27
|
-
|
28
|
-
chs = {}
|
29
|
-
concurrency.times do |i|
|
30
|
-
chs[i] = connection.create_channel
|
31
|
-
end
|
32
|
-
|
33
|
-
ts = []
|
34
|
-
|
35
|
-
concurrency.times do |i|
|
36
|
-
t = Thread.new do
|
37
|
-
cht = chs[i]
|
38
|
-
x = ch.default_exchange
|
39
|
-
|
40
|
-
5.times do |i|
|
41
|
-
rate.times do
|
42
|
-
x.publish(body, :routing_key => q.name)
|
43
|
-
end
|
44
|
-
puts "Published #{(i + 1) * rate} messages..."
|
45
|
-
end
|
46
|
-
end
|
47
|
-
t.abort_on_exception = true
|
48
|
-
|
49
|
-
ts << t
|
50
|
-
end
|
51
|
-
|
52
|
-
ts.each do |t|
|
53
|
-
t.join
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
unless defined?(JRUBY_VERSION) && !ENV["FORCE_JRUBY_RUN"]
|
4
|
-
describe Bunny::Session do
|
5
|
-
# creating thousands of connections means creating
|
6
|
-
# twice as many threads and this won't fly with the JVM
|
7
|
-
# in CI containers. MK.
|
8
|
-
n = if defined?(JRUBY_VERSION)
|
9
|
-
250
|
10
|
-
else
|
11
|
-
2500
|
12
|
-
end
|
13
|
-
|
14
|
-
n.times do |i|
|
15
|
-
it "can be closed (take #{i})" do
|
16
|
-
c = Bunny.new(:automatically_recover => false)
|
17
|
-
c.start
|
18
|
-
ch = c.create_channel
|
19
|
-
|
20
|
-
c.should be_connected
|
21
|
-
c.stop
|
22
|
-
c.should be_closed
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "in the single threaded mode" do
|
27
|
-
n.times do |i|
|
28
|
-
it "can be closed (take #{i})" do
|
29
|
-
c = Bunny.new(:automatically_recover => false, :threaded => false)
|
30
|
-
c.start
|
31
|
-
ch = c.create_channel
|
32
|
-
|
33
|
-
c.should be_connected
|
34
|
-
c.stop
|
35
|
-
c.should be_closed
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|