bunny 2.7.4 → 2.22.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 +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,221 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Queue 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 :each do
|
11
|
-
connection.close if connection.open?
|
12
|
-
end
|
13
|
-
|
14
|
-
context "when queue name is specified" do
|
15
|
-
let(:name) { "a queue declared at #{Time.now.to_i}" }
|
16
|
-
|
17
|
-
it "declares a new queue with that name" do
|
18
|
-
ch = connection.create_channel
|
19
|
-
|
20
|
-
q = ch.queue(name)
|
21
|
-
expect(q.name).to eq name
|
22
|
-
|
23
|
-
q.delete
|
24
|
-
ch.close
|
25
|
-
end
|
26
|
-
|
27
|
-
it "caches that queue" do
|
28
|
-
ch = connection.create_channel
|
29
|
-
|
30
|
-
q = ch.queue(name)
|
31
|
-
expect(ch.queue(name).object_id).to eq q.object_id
|
32
|
-
|
33
|
-
q.delete
|
34
|
-
ch.close
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
context "when queue name is passed on as an empty string" do
|
40
|
-
it "uses server-assigned queue name" do
|
41
|
-
ch = connection.create_channel
|
42
|
-
|
43
|
-
q = ch.queue("")
|
44
|
-
expect(q.name).not_to be_empty
|
45
|
-
expect(q.name).to match /^amq.gen.+/
|
46
|
-
expect(q).to be_server_named
|
47
|
-
q.delete
|
48
|
-
|
49
|
-
ch.close
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
context "when queue is declared as durable" do
|
55
|
-
it "declares it as durable" do
|
56
|
-
ch = connection.create_channel
|
57
|
-
|
58
|
-
q = ch.queue("bunny.tests.queues.durable", durable: true)
|
59
|
-
expect(q).to be_durable
|
60
|
-
expect(q).not_to be_auto_delete
|
61
|
-
expect(q).not_to be_exclusive
|
62
|
-
expect(q.arguments).to be_nil
|
63
|
-
q.delete
|
64
|
-
|
65
|
-
ch.close
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
context "when queue is declared as exclusive" do
|
71
|
-
it "declares it as exclusive" do
|
72
|
-
ch = connection.create_channel
|
73
|
-
|
74
|
-
q = ch.queue("bunny.tests.queues.exclusive", exclusive: true)
|
75
|
-
expect(q).to be_exclusive
|
76
|
-
expect(q).not_to be_durable
|
77
|
-
q.delete
|
78
|
-
|
79
|
-
ch.close
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
context "when queue is declared as auto-delete" do
|
85
|
-
it "declares it as auto-delete" do
|
86
|
-
ch = connection.create_channel
|
87
|
-
|
88
|
-
q = ch.queue("bunny.tests.queues.auto-delete", auto_delete: true)
|
89
|
-
expect(q).to be_auto_delete
|
90
|
-
expect(q).not_to be_exclusive
|
91
|
-
expect(q).not_to be_durable
|
92
|
-
q.delete
|
93
|
-
|
94
|
-
ch.close
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
context "when queue is declared with a different set of attributes" do
|
101
|
-
it "raises an exception" do
|
102
|
-
ch = connection.create_channel
|
103
|
-
|
104
|
-
q = ch.queue("bunny.tests.queues.auto-delete", auto_delete: true, durable: false)
|
105
|
-
expect {
|
106
|
-
# force re-declaration
|
107
|
-
ch.queue_declare("bunny.tests.queues.auto-delete", auto_delete: false, durable: true)
|
108
|
-
}.to raise_error(Bunny::PreconditionFailed)
|
109
|
-
|
110
|
-
expect(ch).to be_closed
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
context "when queue is declared with message TTL" do
|
116
|
-
let(:args) do
|
117
|
-
# in ms
|
118
|
-
{"x-message-ttl" => 1000}
|
119
|
-
end
|
120
|
-
|
121
|
-
it "causes all messages in it to have a TTL" do
|
122
|
-
ch = connection.create_channel
|
123
|
-
|
124
|
-
q = ch.queue("bunny.tests.queues.with-arguments.ttl", arguments: args, exclusive: true)
|
125
|
-
expect(q.arguments).to eq args
|
126
|
-
|
127
|
-
q.publish("xyzzy")
|
128
|
-
sleep 0.1
|
129
|
-
|
130
|
-
expect(q.message_count).to eq 1
|
131
|
-
sleep 1.5
|
132
|
-
expect(q.message_count).to eq 0
|
133
|
-
|
134
|
-
ch.close
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
context "when queue is declared with priorities" do
|
140
|
-
let(:args) do
|
141
|
-
{"x-max-priority" => 5}
|
142
|
-
end
|
143
|
-
|
144
|
-
it "enables priority implementation" do
|
145
|
-
c = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
146
|
-
c.start
|
147
|
-
|
148
|
-
ch = c.create_channel
|
149
|
-
ch.confirm_select
|
150
|
-
|
151
|
-
q = ch.queue("bunny.tests.queues.with-arguments.priority #{rand}", arguments: args, exclusive: true)
|
152
|
-
expect(q.arguments).to eq args
|
153
|
-
|
154
|
-
q.publish("xyzzy")
|
155
|
-
ch.wait_for_confirms
|
156
|
-
sleep 0.1
|
157
|
-
|
158
|
-
# this test only does sanity checking,
|
159
|
-
# without trying to actually test prioritisation.
|
160
|
-
#
|
161
|
-
# added to guard against issues such as
|
162
|
-
# https://github.com/rabbitmq/rabbitmq-server/issues/488
|
163
|
-
expect(q.message_count).to eq 1
|
164
|
-
|
165
|
-
ch.close
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
|
170
|
-
describe "#queue_exists?" do
|
171
|
-
context "when a queue exists" do
|
172
|
-
it "returns true" do
|
173
|
-
ch = connection.create_channel
|
174
|
-
q = ch.queue("", exlusive: true)
|
175
|
-
|
176
|
-
expect(connection.queue_exists?(q.name)).to eq true
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
context "when a queue DOES NOT exist" do
|
181
|
-
it "returns false" do
|
182
|
-
expect(connection.queue_exists?("suf89u9a4jo3ndnakls##{Time.now.to_i}")).to eq false
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
unless ENV["CI"]
|
190
|
-
# requires RabbitMQ 3.1+
|
191
|
-
context "when queue is declared with bounded length" do
|
192
|
-
let(:n) { 10 }
|
193
|
-
let(:args) do
|
194
|
-
# in ms
|
195
|
-
{"x-max-length" => n}
|
196
|
-
end
|
197
|
-
|
198
|
-
# see http://www.rabbitmq.com/maxlength.html for more info
|
199
|
-
it "causes the queue to be bounded" do
|
200
|
-
ch = connection.create_channel
|
201
|
-
|
202
|
-
q = ch.queue("bunny.tests.queues.with-arguments.max-length", arguments: args, exclusive: true)
|
203
|
-
expect(q.arguments).to eq args
|
204
|
-
|
205
|
-
(n * 10).times do
|
206
|
-
q.publish("xyzzy")
|
207
|
-
end
|
208
|
-
|
209
|
-
expect(q.message_count).to eq n
|
210
|
-
(n * 5).times do
|
211
|
-
q.publish("xyzzy")
|
212
|
-
end
|
213
|
-
|
214
|
-
expect(q.message_count).to eq n
|
215
|
-
q.delete
|
216
|
-
|
217
|
-
ch.close
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Queue, "#delete" 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
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
context "with a name of an existing queue" do
|
17
|
-
it "deletes that queue" do
|
18
|
-
ch = connection.create_channel
|
19
|
-
q = ch.queue("")
|
20
|
-
|
21
|
-
q.delete
|
22
|
-
# no exception as of RabbitMQ 3.2. MK.
|
23
|
-
q.delete
|
24
|
-
|
25
|
-
expect(ch.queues.size).to eq 0
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
context "with a name of an existing queue" do
|
31
|
-
it "DOES NOT raise an exception" do
|
32
|
-
ch = connection.create_channel
|
33
|
-
|
34
|
-
# no exception as of RabbitMQ 3.2. MK.
|
35
|
-
ch.queue_delete("sdkhflsdjflskdjflsd#{rand}")
|
36
|
-
ch.queue_delete("sdkhflsdjflskdjflsd#{rand}")
|
37
|
-
ch.queue_delete("sdkhflsdjflskdjflsd#{rand}")
|
38
|
-
ch.queue_delete("sdkhflsdjflskdjflsd#{rand}")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe 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
|
-
after :each do
|
11
|
-
connection.close
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
it "can be purged" do
|
16
|
-
ch = connection.create_channel
|
17
|
-
|
18
|
-
q = ch.queue("", exclusive: true)
|
19
|
-
x = ch.default_exchange
|
20
|
-
|
21
|
-
x.publish("xyzzy", routing_key: q.name)
|
22
|
-
sleep(0.5)
|
23
|
-
|
24
|
-
expect(q.message_count).to eq 1
|
25
|
-
q.purge
|
26
|
-
expect(q.message_count).to eq 0
|
27
|
-
|
28
|
-
ch.close
|
29
|
-
end
|
30
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Queue, "bound to an exchange" 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
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
it "can be unbound from an exchange it was bound to" do
|
16
|
-
ch = connection.create_channel
|
17
|
-
x = ch.fanout("amq.fanout")
|
18
|
-
q = ch.queue("", exclusive: true).bind(x)
|
19
|
-
|
20
|
-
x.publish("")
|
21
|
-
sleep 0.3
|
22
|
-
expect(q.message_count).to eq 1
|
23
|
-
|
24
|
-
q.unbind(x)
|
25
|
-
|
26
|
-
x.publish("")
|
27
|
-
expect(q.message_count).to eq 1
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
describe Bunny::Queue, "NOT bound to an exchange" do
|
34
|
-
let(:connection) do
|
35
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
36
|
-
c.start
|
37
|
-
c
|
38
|
-
end
|
39
|
-
|
40
|
-
after :each do
|
41
|
-
connection.close
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
it "is idempotent (succeeds)" do
|
46
|
-
ch = connection.create_channel
|
47
|
-
x = ch.fanout("amq.fanout")
|
48
|
-
q = ch.queue("", exclusive: true)
|
49
|
-
|
50
|
-
# No exception as of RabbitMQ 3.2. MK.
|
51
|
-
q.unbind(x)
|
52
|
-
q.unbind(x)
|
53
|
-
end
|
54
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Queue, "#subscribe" do
|
4
|
-
let(:publisher_connection) do
|
5
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:consumer_connection) do
|
11
|
-
c = Bunny.new(username: "bunny_reader", password: "reader_password", vhost: "bunny_testbed")
|
12
|
-
c.start
|
13
|
-
c
|
14
|
-
end
|
15
|
-
|
16
|
-
after :each do
|
17
|
-
publisher_connection.close if publisher_connection.open?
|
18
|
-
consumer_connection.close if consumer_connection.open?
|
19
|
-
end
|
20
|
-
|
21
|
-
context "with automatic acknowledgement mode" do
|
22
|
-
let(:queue_name) { "bunny.basic_consume#{rand}" }
|
23
|
-
|
24
|
-
it "registers the consumer" do
|
25
|
-
delivered_keys = []
|
26
|
-
delivered_data = []
|
27
|
-
|
28
|
-
ch = publisher_connection.create_channel
|
29
|
-
# declare the queue because the read-only user won't be able to issue
|
30
|
-
# queue.declare
|
31
|
-
q = ch.queue(queue_name, auto_delete: true, durable: false)
|
32
|
-
|
33
|
-
t = Thread.new do
|
34
|
-
# give the main thread a bit of time to declare the queue
|
35
|
-
sleep 0.5
|
36
|
-
ch = consumer_connection.create_channel
|
37
|
-
# this connection is read only, use passive declare to only get
|
38
|
-
# a reference to the queue
|
39
|
-
q = ch.queue(queue_name, auto_delete: true, durable: false, passive: true)
|
40
|
-
q.subscribe(exclusive: false) do |delivery_info, properties, payload|
|
41
|
-
delivered_keys << delivery_info.routing_key
|
42
|
-
delivered_data << payload
|
43
|
-
end
|
44
|
-
end
|
45
|
-
t.abort_on_exception = true
|
46
|
-
sleep 0.5
|
47
|
-
|
48
|
-
x = ch.default_exchange
|
49
|
-
x.publish("hello", routing_key: queue_name)
|
50
|
-
|
51
|
-
sleep 0.7
|
52
|
-
expect(delivered_keys).to include(queue_name)
|
53
|
-
expect(delivered_data).to include("hello")
|
54
|
-
|
55
|
-
expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0
|
56
|
-
|
57
|
-
ch.close
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end # describe
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Sender-selected distribution" 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 "lets publishers specify additional routing keys using CC and BCC headers" do
|
15
|
-
ch = connection.create_channel
|
16
|
-
x = ch.direct("bunny.tests.ssd.exchange")
|
17
|
-
q1 = ch.queue("", exclusive: true).bind(x, routing_key: "one")
|
18
|
-
q2 = ch.queue("", exclusive: true).bind(x, routing_key: "two")
|
19
|
-
q3 = ch.queue("", exclusive: true).bind(x, routing_key: "three")
|
20
|
-
q4 = ch.queue("", exclusive: true).bind(x, routing_key: "four")
|
21
|
-
|
22
|
-
n = 10
|
23
|
-
n.times do |i|
|
24
|
-
x.publish("Message #{i}", routing_key: "one", headers: {"CC" => ["two", "three"]})
|
25
|
-
end
|
26
|
-
|
27
|
-
sleep 0.5
|
28
|
-
|
29
|
-
expect(q1.message_count).to eq n
|
30
|
-
expect(q2.message_count).to eq n
|
31
|
-
expect(q3.message_count).to eq n
|
32
|
-
expect(q4.message_count).to be_zero
|
33
|
-
|
34
|
-
x.delete
|
35
|
-
end
|
36
|
-
end
|
@@ -1,222 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
unless ENV["CI"]
|
5
|
-
CERTIFICATE_DIR=ENV.fetch("BUNNY_CERTIFICATE_DIR", "./spec/tls")
|
6
|
-
puts "Will use certificates from #{CERTIFICATE_DIR}"
|
7
|
-
|
8
|
-
shared_examples_for "successful TLS connection" do
|
9
|
-
it "succeeds" do
|
10
|
-
expect(subject).to be_tls
|
11
|
-
ch = subject.create_channel
|
12
|
-
ch.confirm_select
|
13
|
-
|
14
|
-
q = ch.queue("", exclusive: true)
|
15
|
-
x = ch.default_exchange
|
16
|
-
|
17
|
-
x.publish("xyzzy", routing_key: q.name).
|
18
|
-
publish("xyzzy", routing_key: q.name).
|
19
|
-
publish("xyzzy", routing_key: q.name).
|
20
|
-
publish("xyzzy", routing_key: q.name)
|
21
|
-
|
22
|
-
x.wait_for_confirms
|
23
|
-
expect(q.message_count).to eq 4
|
24
|
-
|
25
|
-
i = 0
|
26
|
-
q.subscribe do |delivery_info, _, payload|
|
27
|
-
i += 1
|
28
|
-
end
|
29
|
-
sleep 1.0
|
30
|
-
expect(i).to eq 4
|
31
|
-
expect(q.message_count).to eq 0
|
32
|
-
|
33
|
-
ch.close
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def local_hostname
|
38
|
-
ENV.fetch("BUNNY_RABBITMQ_HOSTNAME", "127.0.0.1")
|
39
|
-
end
|
40
|
-
|
41
|
-
context "initialized with :tls => true" do
|
42
|
-
let(:subject) do
|
43
|
-
Bunny.new(:user => "bunny_gem",
|
44
|
-
:password => "bunny_password",
|
45
|
-
:vhost => "bunny_testbed",
|
46
|
-
:tls => true,
|
47
|
-
:verify_peer => verify_peer,
|
48
|
-
:tls_cert => "#{CERTIFICATE_DIR}/client_certificate.pem",
|
49
|
-
:tls_key => "#{CERTIFICATE_DIR}/client_key.pem",
|
50
|
-
:tls_ca_certificates => ["#{CERTIFICATE_DIR}/ca_certificate.pem"])
|
51
|
-
end
|
52
|
-
|
53
|
-
context "peer verification is off" do
|
54
|
-
let(:verify_peer) { false }
|
55
|
-
|
56
|
-
it "uses TLS port" do
|
57
|
-
expect(subject.port).to eq AMQ::Protocol::TLS_PORT
|
58
|
-
end
|
59
|
-
|
60
|
-
it "sends the SNI details" do
|
61
|
-
# https://github.com/ruby-amqp/bunny/issues/440
|
62
|
-
subject.start
|
63
|
-
expect(subject.transport.socket.hostname).to_not be_empty
|
64
|
-
end
|
65
|
-
|
66
|
-
after :each do
|
67
|
-
subject.close
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "peer verification is on" do
|
72
|
-
let(:verify_peer) { true }
|
73
|
-
|
74
|
-
it "uses TLS port" do
|
75
|
-
expect(subject.port).to eq AMQ::Protocol::TLS_PORT
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "TLS connection to RabbitMQ with client certificates" do
|
81
|
-
let(:subject) do
|
82
|
-
c = Bunny.new(username: "bunny_gem",
|
83
|
-
password: "bunny_password",
|
84
|
-
vhost: "bunny_testbed",
|
85
|
-
tls: true,
|
86
|
-
tls_cert: "#{CERTIFICATE_DIR}/client_certificate.pem",
|
87
|
-
tls_key: "#{CERTIFICATE_DIR}/client_key.pem",
|
88
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
89
|
-
verify_peer: false)
|
90
|
-
c.start
|
91
|
-
c
|
92
|
-
end
|
93
|
-
|
94
|
-
after :each do
|
95
|
-
subject.close
|
96
|
-
end
|
97
|
-
|
98
|
-
include_examples "successful TLS connection"
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
describe "TLS connection to RabbitMQ without client certificates" do
|
103
|
-
let(:subject) do
|
104
|
-
c = Bunny.new(username: "bunny_gem",
|
105
|
-
password: "bunny_password",
|
106
|
-
vhost: "bunny_testbed",
|
107
|
-
tls: true,
|
108
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
109
|
-
verify_peer: false)
|
110
|
-
c.start
|
111
|
-
c
|
112
|
-
end
|
113
|
-
|
114
|
-
after :each do
|
115
|
-
subject.close
|
116
|
-
end
|
117
|
-
|
118
|
-
include_examples "successful TLS connection"
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
describe "TLS connection to RabbitMQ with a connection string" do
|
123
|
-
let(:subject) do
|
124
|
-
c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname}/bunny_testbed",
|
125
|
-
tls_cert: "#{CERTIFICATE_DIR}/client_certificate.pem",
|
126
|
-
tls_key: "#{CERTIFICATE_DIR}/client_key.pem",
|
127
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
128
|
-
verify_peer: false)
|
129
|
-
c.start
|
130
|
-
c
|
131
|
-
end
|
132
|
-
|
133
|
-
after :each do
|
134
|
-
subject.close
|
135
|
-
end
|
136
|
-
|
137
|
-
include_examples "successful TLS connection"
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
describe "TLS connection to RabbitMQ with a connection string and w/o client certificate and key" do
|
142
|
-
let(:subject) do
|
143
|
-
c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname}/bunny_testbed",
|
144
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
145
|
-
verify_peer: verify_peer)
|
146
|
-
c.start
|
147
|
-
c
|
148
|
-
end
|
149
|
-
|
150
|
-
after :each do
|
151
|
-
subject.close
|
152
|
-
end
|
153
|
-
|
154
|
-
context "peer verification is off" do
|
155
|
-
let(:verify_peer) { false }
|
156
|
-
|
157
|
-
include_examples "successful TLS connection"
|
158
|
-
|
159
|
-
it "sends the SNI details" do
|
160
|
-
# https://github.com/ruby-amqp/bunny/issues/440
|
161
|
-
expect(subject.transport.socket.hostname).to_not be_empty
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context "peer verification is on" do
|
166
|
-
let(:verify_peer) { true }
|
167
|
-
|
168
|
-
include_examples "successful TLS connection"
|
169
|
-
|
170
|
-
it "sends the SNI details" do
|
171
|
-
# https://github.com/ruby-amqp/bunny/issues/440
|
172
|
-
expect(subject.transport.socket.hostname).to_not be_empty
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
|
178
|
-
describe "TLS connection to RabbitMQ with client certificates provided inline" do
|
179
|
-
let(:subject) do
|
180
|
-
c = Bunny.new(username: "bunny_gem",
|
181
|
-
password: "bunny_password",
|
182
|
-
vhost: "bunny_testbed",
|
183
|
-
tls: true,
|
184
|
-
tls_cert: File.read("#{CERTIFICATE_DIR}/client_certificate.pem"),
|
185
|
-
tls_key: File.read("#{CERTIFICATE_DIR}/client_key.pem"),
|
186
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
187
|
-
verify_peer: false)
|
188
|
-
c.start
|
189
|
-
c
|
190
|
-
end
|
191
|
-
|
192
|
-
after :each do
|
193
|
-
subject.close
|
194
|
-
end
|
195
|
-
|
196
|
-
include_examples "successful TLS connection"
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "TLS connection to RabbitMQ with tls_version TLSv1.1 specified" do
|
200
|
-
let(:subject) do
|
201
|
-
c = Bunny.new(username: "bunny_gem",
|
202
|
-
password: "bunny_password",
|
203
|
-
vhost: "bunny_testbed",
|
204
|
-
tls: true,
|
205
|
-
tls_protocol: :TLSv1_1,
|
206
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
207
|
-
verify_peer: false)
|
208
|
-
c.start
|
209
|
-
c
|
210
|
-
end
|
211
|
-
|
212
|
-
after :each do
|
213
|
-
subject.close
|
214
|
-
end
|
215
|
-
|
216
|
-
include_examples "successful TLS connection"
|
217
|
-
|
218
|
-
it "connects using TLSv1.1" do
|
219
|
-
expect(subject.transport.socket.ssl_version).to eq "TLSv1.1"
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#tx_commit" 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 "is supported" do
|
15
|
-
ch = connection.create_channel
|
16
|
-
ch.tx_select
|
17
|
-
ch.tx_commit
|
18
|
-
|
19
|
-
ch.close
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#tx_rollback" 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 "is supported" do
|
15
|
-
ch = connection.create_channel
|
16
|
-
ch.tx_select
|
17
|
-
ch.tx_rollback
|
18
|
-
|
19
|
-
ch.close
|
20
|
-
end
|
21
|
-
end
|