Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 250a3ba

Browse files
committed
Add DEFAULT_EXCHANGE and AVAILABILITY_ERRORS constants.
1 parent dafdba3 commit 250a3ba

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require 'rabbitmq'
3535

3636
publisher = RabbitMQ::Client.new.start.channel
3737
queue = "some_queue"
38-
exchange = ""# default exchange
38+
exchange = RabbitMQ::DEFAULT_EXCHANGE
3939
publisher.queue_delete(queue)
4040
publisher.queue_declare(queue)
4141

‎example/memory/publisher.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
publisher = RabbitMQ::Client.new.start.channel
1111
queue = "memory_queue"
12-
exchange = ""# default exchange
12+
exchange = RabbitMQ::DEFAULT_EXCHANGE
1313
publisher.queue_declare(queue)
1414

1515
while true

‎example/publish_500.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
publisher = RabbitMQ::Client.new.start.channel
55
queue = "some_queue"
6-
exchange = ""# default exchange
6+
exchange = RabbitMQ::DEFAULT_EXCHANGE
77
publisher.queue_delete(queue)
88
publisher.queue_declare(queue)
99

‎lib/rabbitmq.rb‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,18 @@
99

1010
require_relative 'rabbitmq/client'
1111
require_relative 'rabbitmq/channel'
12+
13+
14+
module RabbitMQ
15+
# The RabbitMQ default exchange.
16+
DEFAULT_EXCHANGE = "".freeze
17+
18+
# An array of errors that indicate an availabilty issue.
19+
AVAILABILITY_ERRORS = [
20+
RabbitMQ::ServerError::ConnectionError,
21+
RabbitMQ::FFI::Error::Timeout,
22+
RabbitMQ::FFI::Error::ConnectionClosed,
23+
RabbitMQ::FFI::Error::SocketError,
24+
RabbitMQ::FFI::Error::BadAmqpData,
25+
].freeze
26+
end

‎spec/channel_spec.rb‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@
192192
subject.queue_delete("my_queue")
193193
subject.queue_declare("my_queue")
194194

195-
res = subject.basic_publish("message_body", "","my_queue",
196-
persistent: true, priority: 5)
195+
res = subject.basic_publish("message_body", RabbitMQ::DEFAULT_EXCHANGE,
196+
"my_queue",persistent: true, priority: 5)
197197
res.should eq true
198198

199199
res = subject.basic_get("my_queue", no_ack: true)
200200
res[:method].should eq :basic_get_ok
201201
res[:properties].delete(:delivery_tag) .should be_an Integer
202202
res[:properties].delete(:redelivered) .should eq false
203-
res[:properties].delete(:exchange) .should eq ""
203+
res[:properties].delete(:exchange) .should eq RabbitMQ::DEFAULT_EXCHANGE
204204
res[:properties].delete(:routing_key) .should eq "my_queue"
205205
res[:properties].delete(:message_count).should eq 0
206206
res[:properties].should be_empty
@@ -222,7 +222,7 @@
222222

223223
# Publish some messages to the queue
224224
10.times do |i|
225-
subject.basic_publish("message_#{i}", "", "my_queue")
225+
subject.basic_publish("message_#{i}", RabbitMQ::DEFAULT_EXCHANGE, "my_queue")
226226
end
227227

228228
# Negotiate this channel as a consumer of the queue
@@ -240,7 +240,7 @@
240240

241241
res[:method].should eq :basic_deliver
242242
res[:properties].delete(:redelivered).should eq false
243-
res[:properties].delete(:exchange) .should eq ""
243+
res[:properties].delete(:exchange) .should eq RabbitMQ::DEFAULT_EXCHANGE
244244
res[:properties].delete(:routing_key).should eq "my_queue"
245245
res[:properties].should be_empty
246246
res[:header].should be_a Hash

‎spec/rabbitmq_spec.rb‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
require 'spec_helper'
3+
4+
5+
describe RabbitMQ do
6+
describe "DEFAULT_EXCHANGE" do
7+
subject { RabbitMQ::DEFAULT_EXCHANGE }
8+
9+
it { should eq "" }
10+
end
11+
12+
describe "AVAILABILITY_ERRORS" do
13+
subject { RabbitMQ::AVAILABILITY_ERRORS }
14+
15+
it { should be_an Array }
16+
it { should_not be_empty }
17+
18+
specify "each element is a subclass of Exception" do
19+
subject.all? { |e| e < Exception }.should be true
20+
end
21+
end
22+
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /