amq-client 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.gitmodules +9 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +1 -0
- data/CONTRIBUTORS +3 -0
- data/Gemfile +27 -0
- data/LICENSE +20 -0
- data/README.textile +61 -0
- data/amq-client.gemspec +34 -0
- data/bin/jenkins.sh +23 -0
- data/bin/set_test_suite_realms_up.sh +24 -0
- data/examples/coolio_adapter/basic_consume.rb +49 -0
- data/examples/coolio_adapter/basic_consume_with_acknowledgements.rb +43 -0
- data/examples/coolio_adapter/basic_consume_with_rejections.rb +43 -0
- data/examples/coolio_adapter/basic_publish.rb +35 -0
- data/examples/coolio_adapter/channel_close.rb +24 -0
- data/examples/coolio_adapter/example_helper.rb +39 -0
- data/examples/coolio_adapter/exchange_declare.rb +28 -0
- data/examples/coolio_adapter/kitchen_sink1.rb +48 -0
- data/examples/coolio_adapter/queue_bind.rb +32 -0
- data/examples/coolio_adapter/queue_purge.rb +32 -0
- data/examples/coolio_adapter/queue_unbind.rb +37 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_custom_role_credentials.rb +36 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_default_role_credentials.rb +27 -0
- data/examples/eventmachine_adapter/authentication/plain_password_with_incorrect_credentials.rb +18 -0
- data/examples/eventmachine_adapter/basic_cancel.rb +49 -0
- data/examples/eventmachine_adapter/basic_consume.rb +51 -0
- data/examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb +45 -0
- data/examples/eventmachine_adapter/basic_consume_with_rejections.rb +45 -0
- data/examples/eventmachine_adapter/basic_get.rb +57 -0
- data/examples/eventmachine_adapter/basic_get_with_empty_queue.rb +53 -0
- data/examples/eventmachine_adapter/basic_publish.rb +38 -0
- data/examples/eventmachine_adapter/basic_qos.rb +29 -0
- data/examples/eventmachine_adapter/basic_recover.rb +29 -0
- data/examples/eventmachine_adapter/basic_return.rb +34 -0
- data/examples/eventmachine_adapter/channel_close.rb +24 -0
- data/examples/eventmachine_adapter/channel_flow.rb +36 -0
- data/examples/eventmachine_adapter/channel_level_exception_handling.rb +44 -0
- data/examples/eventmachine_adapter/example_helper.rb +39 -0
- data/examples/eventmachine_adapter/exchange_declare.rb +54 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/handling_confirm_select_ok.rb +31 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/publisher_confirmations_with_transient_messages.rb +56 -0
- data/examples/eventmachine_adapter/extensions/rabbitmq/publisher_confirmations_with_unroutable_message.rb +46 -0
- data/examples/eventmachine_adapter/kitchen_sink1.rb +50 -0
- data/examples/eventmachine_adapter/queue_bind.rb +32 -0
- data/examples/eventmachine_adapter/queue_declare.rb +34 -0
- data/examples/eventmachine_adapter/queue_purge.rb +32 -0
- data/examples/eventmachine_adapter/queue_unbind.rb +37 -0
- data/examples/eventmachine_adapter/tx_commit.rb +29 -0
- data/examples/eventmachine_adapter/tx_rollback.rb +29 -0
- data/examples/eventmachine_adapter/tx_select.rb +27 -0
- data/examples/socket_adapter/basics.rb +19 -0
- data/examples/socket_adapter/connection.rb +53 -0
- data/examples/socket_adapter/multiple_connections.rb +17 -0
- data/irb.rb +66 -0
- data/lib/amq/client.rb +15 -0
- data/lib/amq/client/adapter.rb +356 -0
- data/lib/amq/client/adapters/coolio.rb +221 -0
- data/lib/amq/client/adapters/event_machine.rb +228 -0
- data/lib/amq/client/adapters/socket.rb +89 -0
- data/lib/amq/client/channel.rb +338 -0
- data/lib/amq/client/connection.rb +246 -0
- data/lib/amq/client/entity.rb +117 -0
- data/lib/amq/client/exceptions.rb +86 -0
- data/lib/amq/client/exchange.rb +163 -0
- data/lib/amq/client/extensions/rabbitmq.rb +5 -0
- data/lib/amq/client/extensions/rabbitmq/basic.rb +36 -0
- data/lib/amq/client/extensions/rabbitmq/confirm.rb +254 -0
- data/lib/amq/client/framing/io/frame.rb +32 -0
- data/lib/amq/client/framing/string/frame.rb +62 -0
- data/lib/amq/client/logging.rb +56 -0
- data/lib/amq/client/mixins/anonymous_entity.rb +21 -0
- data/lib/amq/client/mixins/status.rb +62 -0
- data/lib/amq/client/protocol/get_response.rb +55 -0
- data/lib/amq/client/queue.rb +450 -0
- data/lib/amq/client/settings.rb +83 -0
- data/lib/amq/client/version.rb +5 -0
- data/spec/benchmarks/adapters.rb +77 -0
- data/spec/client/framing/io_frame_spec.rb +57 -0
- data/spec/client/framing/string_frame_spec.rb +57 -0
- data/spec/client/protocol/get_response_spec.rb +79 -0
- data/spec/integration/coolio/basic_ack_spec.rb +41 -0
- data/spec/integration/coolio/basic_get_spec.rb +73 -0
- data/spec/integration/coolio/basic_return_spec.rb +33 -0
- data/spec/integration/coolio/channel_close_spec.rb +26 -0
- data/spec/integration/coolio/channel_flow_spec.rb +46 -0
- data/spec/integration/coolio/spec_helper.rb +31 -0
- data/spec/integration/coolio/tx_commit_spec.rb +40 -0
- data/spec/integration/coolio/tx_rollback_spec.rb +44 -0
- data/spec/integration/eventmachine/basic_ack_spec.rb +40 -0
- data/spec/integration/eventmachine/basic_get_spec.rb +73 -0
- data/spec/integration/eventmachine/basic_return_spec.rb +35 -0
- data/spec/integration/eventmachine/channel_close_spec.rb +26 -0
- data/spec/integration/eventmachine/channel_flow_spec.rb +32 -0
- data/spec/integration/eventmachine/spec_helper.rb +22 -0
- data/spec/integration/eventmachine/tx_commit_spec.rb +47 -0
- data/spec/integration/eventmachine/tx_rollback_spec.rb +35 -0
- data/spec/regression/bad_frame_slicing_in_adapters_spec.rb +59 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/unit/client/adapter_spec.rb +49 -0
- data/spec/unit/client/entity_spec.rb +49 -0
- data/spec/unit/client/logging_spec.rb +60 -0
- data/spec/unit/client/mixins/status_spec.rb +72 -0
- data/spec/unit/client/settings_spec.rb +27 -0
- data/spec/unit/client_spec.rb +11 -0
- data/tasks.rb +11 -0
- metadata +202 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "amq/protocol/client" # TODO: "amq/protocol/constants"
|
4
|
+
|
5
|
+
module AMQ
|
6
|
+
module Client
|
7
|
+
# @see AMQ::Client::Settings.configure
|
8
|
+
module Settings
|
9
|
+
# Default connection settings used by AMQ clients
|
10
|
+
#
|
11
|
+
# @see AMQ::Client::Settings.configure
|
12
|
+
def self.default
|
13
|
+
{
|
14
|
+
# server
|
15
|
+
:host => "127.0.0.1",
|
16
|
+
:port => AMQ::Protocol::DEFAULT_PORT,
|
17
|
+
|
18
|
+
# login
|
19
|
+
:user => "guest",
|
20
|
+
:pass => "guest",
|
21
|
+
:vhost => "/",
|
22
|
+
|
23
|
+
# connection timeout
|
24
|
+
:timeout => nil,
|
25
|
+
|
26
|
+
# logging
|
27
|
+
:logging => false,
|
28
|
+
|
29
|
+
# ssl
|
30
|
+
:ssl => false,
|
31
|
+
|
32
|
+
# broker
|
33
|
+
# if you want to load broker-specific extensions
|
34
|
+
:broker => nil,
|
35
|
+
|
36
|
+
:frame_max => 131072
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
# Merges given configuration parameters with defaults and returns
|
41
|
+
# the result.
|
42
|
+
#
|
43
|
+
# @param [Hash] Configuration parameters to use.
|
44
|
+
#
|
45
|
+
# @option settings [String] :host ("127.0.0.1") Hostname AMQ broker runs on.
|
46
|
+
# @option settings [String] :port (5672) Port AMQ broker listens on.
|
47
|
+
# @option settings [String] :vhost ("/") Virtual host to use.
|
48
|
+
# @option settings [String] :user ("guest") Username to use for authentication.
|
49
|
+
# @option settings [String] :pass ("guest") Password to use for authentication.
|
50
|
+
# @option settings [String] :ssl (false) Should be use TLS (SSL) for connection?
|
51
|
+
# @option settings [String] :timeout (nil) Connection timeout.
|
52
|
+
# @option settings [String] :logging (false) Turns logging on or off.
|
53
|
+
# @option settings [String] :broker (nil) Broker name (use if you intend to use broker-specific features).
|
54
|
+
# @option settings [Fixnum] :frame_max (131072) Maximum frame size to use. If broker cannot support frames this large, broker's maximum value will be used instead.
|
55
|
+
#
|
56
|
+
# @return [Hash] Merged configuration parameters.
|
57
|
+
def self.configure(settings = nil)
|
58
|
+
case settings
|
59
|
+
when Hash then
|
60
|
+
if username = settings.delete(:username)
|
61
|
+
settings[:user] ||= username
|
62
|
+
end
|
63
|
+
|
64
|
+
if password = settings.delete(:password)
|
65
|
+
settings[:pass] ||= password
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
self.default.merge(settings)
|
70
|
+
when String then
|
71
|
+
settings = self.parse_amqp_url(settings)
|
72
|
+
self.default.merge(settings)
|
73
|
+
when NilClass then
|
74
|
+
self.default
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.parse_amqp_url(string)
|
79
|
+
raise NotImplementedError.new
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
Bundler.setup
|
2
|
+
Bundler.require(:default)
|
3
|
+
$LOAD_PATH.unshift(File.expand_path("../../../lib", __FILE__))
|
4
|
+
|
5
|
+
require "amq/client/adapters/coolio"
|
6
|
+
require "amq/client/adapters/event_machine"
|
7
|
+
require "amq/client/queue"
|
8
|
+
require "amq/client/exchange"
|
9
|
+
|
10
|
+
TOTAL_MESSAGES = 10000
|
11
|
+
# Short messages
|
12
|
+
# Cool.io
|
13
|
+
coolio_start = Time.now
|
14
|
+
AMQ::Client::Coolio.connect(:port => 5672, :vhost => "/amq_client_testbed") do |client|
|
15
|
+
received_messages = 0
|
16
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
17
|
+
channel.open { }
|
18
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
19
|
+
queue.declare(false, false, false, true) { }
|
20
|
+
|
21
|
+
queue.bind("amq.fanout") { }
|
22
|
+
|
23
|
+
queue.consume(true) do |_, consumer_tag|
|
24
|
+
|
25
|
+
queue.on_delivery do |_, header, payload, consumer_tag, delivery_tag, redelivered, exchange, routing_key|
|
26
|
+
received_messages += 1
|
27
|
+
if received_messages == TOTAL_MESSAGES
|
28
|
+
client.disconnect do
|
29
|
+
Coolio::Loop.default.stop
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
35
|
+
TOTAL_MESSAGES.times do |i|
|
36
|
+
exchange.publish("Message ##{i}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
cool.io.run
|
41
|
+
coolio_finish = Time.now
|
42
|
+
|
43
|
+
# Eventmachine
|
44
|
+
em_start = Time.now
|
45
|
+
EM.run do
|
46
|
+
AMQ::Client::EventMachineClient.connect(:port => 5672, :vhost => "/amq_client_testbed") do |client|
|
47
|
+
received_messages = 0
|
48
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
49
|
+
channel.open { }
|
50
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
51
|
+
queue.declare(false, false, false, true) { }
|
52
|
+
|
53
|
+
queue.bind("amq.fanout") { }
|
54
|
+
|
55
|
+
queue.consume(true) do |_, consumer_tag|
|
56
|
+
|
57
|
+
queue.on_delivery do |_, header, payload, consumer_tag, delivery_tag, redelivered, exchange, routing_key|
|
58
|
+
received_messages += 1
|
59
|
+
if received_messages == TOTAL_MESSAGES
|
60
|
+
client.disconnect do
|
61
|
+
EM.stop
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
67
|
+
TOTAL_MESSAGES.times do |i|
|
68
|
+
exchange.publish("Message ##{i}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
em_finish = Time.now
|
74
|
+
|
75
|
+
puts "Results for #{TOTAL_MESSAGES} messages:"
|
76
|
+
puts "\tcool.io adapter: #{sprintf("%.3f", coolio_finish - coolio_start)}s"
|
77
|
+
puts "\teventmachine adapter: #{sprintf("%.3f", em_finish - em_start)}s"
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: binary
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "stringio"
|
5
|
+
|
6
|
+
# We need to require AMQ-Protocol manually.
|
7
|
+
# In the library this is required in the file
|
8
|
+
# amq/client.rb, but this is a unit test and
|
9
|
+
# we don't want to mess around with unecessary
|
10
|
+
# dependencies.
|
11
|
+
require "amq/protocol/client"
|
12
|
+
require "amq/protocol/frame"
|
13
|
+
|
14
|
+
# We have to use Kernel#load so extensions to the
|
15
|
+
# Logging module from client.rb will be overridden.
|
16
|
+
load "amq/client/framing/io/frame.rb"
|
17
|
+
|
18
|
+
describe AMQ::Client::Framing::IO do
|
19
|
+
subject do
|
20
|
+
AMQ::Client::Framing::IO::Frame
|
21
|
+
end
|
22
|
+
|
23
|
+
# Created by:
|
24
|
+
# frame = AMQ::Protocol::Queue::Declare.encode(1, "tasks", false, false, false, false, {})
|
25
|
+
# frame.encode
|
26
|
+
# frame.payload
|
27
|
+
before do
|
28
|
+
data = ["\x01\x00\x00\x00\x00\x00\b"]
|
29
|
+
data << "\x00\n\x00(\x01/\x00\x00"
|
30
|
+
data << "\xCE"
|
31
|
+
@io = StringIO.new(data.join)
|
32
|
+
|
33
|
+
subject.stub(:decode_header).with(data.first).and_return([1, 0, data[1].bytesize])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to decode frame type" do
|
37
|
+
subject.decode(@io).should be_kind_of(AMQ::Protocol::MethodFrame)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to decode channel" do
|
41
|
+
subject.decode(@io).channel.should eql(0)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be able to decode payload" do
|
45
|
+
subject.decode(@io).payload.should eql("\x00\n\x00(\x01/\x00\x00")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise an error if the frame length is miscalculated" do
|
49
|
+
pending "How to do that with socket?"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should raise an error if the frame doesn't end with FINAL_OCTET" do
|
53
|
+
data = @io.read[0..-2] + "too long" + "\xCE"
|
54
|
+
io = StringIO.new(data)
|
55
|
+
lambda { subject.decode(io) }.should raise_error(AMQ::Client::NoFinalOctetError)
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
# We need to require AMQ-Protocol manually.
|
6
|
+
# In the library this is required in the file
|
7
|
+
# amq/client.rb, but this is a unit test and
|
8
|
+
# we don't want to mess around with unecessary
|
9
|
+
# dependencies.
|
10
|
+
require "amq/protocol/client"
|
11
|
+
require "amq/protocol/frame"
|
12
|
+
|
13
|
+
# We have to use Kernel#load so extensions to the
|
14
|
+
# Logging module from client.rb will be overridden.
|
15
|
+
load "amq/client/framing/string/frame.rb"
|
16
|
+
|
17
|
+
describe AMQ::Client::Framing::String do
|
18
|
+
subject do
|
19
|
+
AMQ::Client::Framing::String::Frame
|
20
|
+
end
|
21
|
+
|
22
|
+
# Created by:
|
23
|
+
# frame = AMQ::Protocol::Queue::Declare.encode(1, "tasks", false, false, false, false, {})
|
24
|
+
# frame.encode
|
25
|
+
# frame.payload
|
26
|
+
before do
|
27
|
+
data = ["\x01\x00\x00\x00\x00\x00\b"]
|
28
|
+
data << "\x00\n\x00(\x01/\x00\x00"
|
29
|
+
data << "\xCE"
|
30
|
+
@string = data.join
|
31
|
+
|
32
|
+
subject.stub(:decode_header).with(data.first).and_return([1, 0, data[1].bytesize])
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be able to decode frame type" do
|
36
|
+
subject.decode(@string).should be_kind_of(AMQ::Protocol::MethodFrame)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be able to decode channel" do
|
40
|
+
subject.decode(@string).channel.should eql(0)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be able to decode payload" do
|
44
|
+
subject.decode(@string).payload.should eql("\x00\n\x00(\x01/\x00\x00")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should raise an error if the frame length is miscalculated" do
|
48
|
+
data = @string[0..-2] + "too long" + "\xCE"
|
49
|
+
string = String.new(data)
|
50
|
+
lambda { subject.decode(string) }.should raise_error(AMQ::Client::BadLengthError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should raise an error if the frame doesn't end with FINAL_OCTET" do
|
54
|
+
string = @string[0..-2] + "x"
|
55
|
+
lambda { subject.decode(string) }.should raise_error(AMQ::Client::NoFinalOctetError)
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
require "amq/protocol/client"
|
6
|
+
require "amq/client/protocol/get_response"
|
7
|
+
# require "amq/protocol/frame"
|
8
|
+
#
|
9
|
+
# # We have to use Kernel#load so extensions to the
|
10
|
+
# # Logging module from client.rb will be overridden.
|
11
|
+
# load "amq/client/framing/string/frame.rb"
|
12
|
+
|
13
|
+
describe AMQ::Protocol::GetResponse do
|
14
|
+
describe "when method is GetOk" do
|
15
|
+
before { @method = AMQ::Protocol::Basic::GetOk.new("dtag", true, "tasks", "foo", 1) }
|
16
|
+
subject { AMQ::Protocol::GetResponse.new(@method) }
|
17
|
+
|
18
|
+
it "should NOT be #empty?" do
|
19
|
+
should_not be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have #delivery_tag" do
|
23
|
+
subject.delivery_tag.should eql("dtag")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have #redelivered" do
|
27
|
+
subject.redelivered.should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have #exchange" do
|
31
|
+
subject.exchange.should eql("tasks")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have #routing_key" do
|
35
|
+
subject.routing_key.should eql("foo")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have #message_count" do
|
39
|
+
subject.message_count.should eql(1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should NOT have #cluster_id" do
|
43
|
+
subject.cluster_id.should be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "when method is GetEmpty" do
|
48
|
+
before { @method = AMQ::Protocol::Basic::GetEmpty.new("ID") }
|
49
|
+
subject { AMQ::Protocol::GetResponse.new(@method) }
|
50
|
+
|
51
|
+
it "should be #empty?" do
|
52
|
+
should be_empty
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should NOT have #delivery_tag" do
|
56
|
+
subject.delivery_tag.should be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should NOT have #redelivered" do
|
60
|
+
subject.redelivered.should be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should NOT have #exchange" do
|
64
|
+
subject.exchange.should be_nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should NOT have #routing_key" do
|
68
|
+
subject.routing_key.should be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should NOT have #message_count" do
|
72
|
+
subject.message_count.should be_nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should have #cluster_id" do
|
76
|
+
subject.cluster_id.should eql("ID")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/coolio/spec_helper'
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'integration/coolio/spec_helper'
|
6
|
+
|
7
|
+
describe "AMQ::Client::Coolio", "Basic.Ack", :nojruby => true do
|
8
|
+
include EventedSpec::SpecHelper
|
9
|
+
default_timeout 1
|
10
|
+
|
11
|
+
context "sending 100 messages" do
|
12
|
+
let(:messages) { (0..99).map {|i| "Message #{i}" } }
|
13
|
+
|
14
|
+
it "should receive & acknowledge all the messages" do
|
15
|
+
@received_messages = []
|
16
|
+
coolio_amqp_connect do |client|
|
17
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
18
|
+
channel.open do
|
19
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
20
|
+
queue.declare.bind("amq.fanout")
|
21
|
+
|
22
|
+
queue.consume do |_, consumer_tag|
|
23
|
+
queue.on_delivery do |method, header, payload|
|
24
|
+
queue.acknowledge(method.delivery_tag)
|
25
|
+
@received_messages << payload
|
26
|
+
end
|
27
|
+
|
28
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
29
|
+
messages.each do |message|
|
30
|
+
exchange.publish(message)
|
31
|
+
end
|
32
|
+
end # consume
|
33
|
+
end # open
|
34
|
+
|
35
|
+
done(0.8) {
|
36
|
+
@received_messages.size.should == messages.size
|
37
|
+
}
|
38
|
+
end # coolio_amqp_connect
|
39
|
+
end # it
|
40
|
+
end # context
|
41
|
+
end # describe
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'integration/coolio/spec_helper'
|
3
|
+
|
4
|
+
describe "AMQ::Client::Coolio", "Basic.Get", :nojruby => true do
|
5
|
+
include EventedSpec::SpecHelper
|
6
|
+
default_timeout 1
|
7
|
+
|
8
|
+
context "when set two messages beforehand" do
|
9
|
+
let(:messages) { ["message 1", "message 2"] }
|
10
|
+
|
11
|
+
it "synchronously fetches all the messages" do
|
12
|
+
@received_messages = []
|
13
|
+
coolio_amqp_connect do |client|
|
14
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
15
|
+
|
16
|
+
channel.open do
|
17
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
18
|
+
queue.declare(false, false, false, true) do
|
19
|
+
queue.bind("amq.fanout")
|
20
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
21
|
+
|
22
|
+
messages.each do |message|
|
23
|
+
exchange.publish(message) do
|
24
|
+
puts "Published a message: #{message}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
queue.get(true) do |method, header, payload|
|
29
|
+
puts "Got #{payload}"
|
30
|
+
@received_messages << payload
|
31
|
+
end
|
32
|
+
queue.get(true) do |method, header, payload|
|
33
|
+
puts "Got #{payload}"
|
34
|
+
@received_messages << payload
|
35
|
+
end
|
36
|
+
|
37
|
+
done(0.5) {
|
38
|
+
@received_messages.should =~ messages
|
39
|
+
|
40
|
+
queue.purge
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
context "when sent no messages beforehand" do
|
50
|
+
it "should receive nils" do
|
51
|
+
coolio_amqp_connect do |client|
|
52
|
+
channel = AMQ::Client::Channel.new(client, 1)
|
53
|
+
channel.open do
|
54
|
+
queue = AMQ::Client::Queue.new(client, channel)
|
55
|
+
queue.declare(false, false, false, true)
|
56
|
+
queue.bind("amq.fanout")
|
57
|
+
|
58
|
+
exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
|
59
|
+
|
60
|
+
queue.get(true) do |method, header, payload|
|
61
|
+
header.should be_nil
|
62
|
+
payload.should be_nil
|
63
|
+
|
64
|
+
done {
|
65
|
+
queue.purge
|
66
|
+
}
|
67
|
+
end # get
|
68
|
+
end
|
69
|
+
end # em_amqp_connect
|
70
|
+
end # it
|
71
|
+
|
72
|
+
end # context
|
73
|
+
end
|