bunny 0.6.3.rc2 → 0.7
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.
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/.yardopts +9 -0
- data/CHANGELOG +3 -0
- data/Gemfile +39 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +5 -4
- data/README.textile +54 -0
- data/Rakefile +15 -13
- data/bunny.gemspec +42 -61
- data/examples/simple_08.rb +4 -2
- data/examples/simple_09.rb +4 -2
- data/examples/simple_ack_08.rb +3 -1
- data/examples/simple_ack_09.rb +3 -1
- data/examples/simple_consumer_08.rb +4 -2
- data/examples/simple_consumer_09.rb +4 -2
- data/examples/simple_fanout_08.rb +3 -1
- data/examples/simple_fanout_09.rb +3 -1
- data/examples/simple_headers_08.rb +5 -3
- data/examples/simple_headers_09.rb +5 -3
- data/examples/simple_publisher_08.rb +3 -1
- data/examples/simple_publisher_09.rb +3 -1
- data/examples/simple_topic_08.rb +5 -3
- data/examples/simple_topic_09.rb +5 -3
- data/ext/amqp-0.8.json +616 -0
- data/ext/amqp-0.9.1.json +388 -0
- data/ext/config.yml +4 -0
- data/ext/qparser.rb +463 -0
- data/lib/bunny.rb +88 -66
- data/lib/bunny/channel08.rb +38 -38
- data/lib/bunny/channel09.rb +37 -37
- data/lib/bunny/client08.rb +184 -206
- data/lib/bunny/client09.rb +277 -363
- data/lib/bunny/consumer.rb +35 -0
- data/lib/bunny/exchange08.rb +37 -41
- data/lib/bunny/exchange09.rb +106 -124
- data/lib/bunny/queue08.rb +216 -202
- data/lib/bunny/queue09.rb +256 -326
- data/lib/bunny/subscription08.rb +30 -29
- data/lib/bunny/subscription09.rb +84 -83
- data/lib/bunny/version.rb +5 -0
- data/lib/qrack/amq-client-url.rb +165 -0
- data/lib/qrack/channel.rb +19 -17
- data/lib/qrack/client.rb +152 -151
- data/lib/qrack/errors.rb +5 -0
- data/lib/qrack/protocol/protocol08.rb +132 -130
- data/lib/qrack/protocol/protocol09.rb +133 -131
- data/lib/qrack/protocol/spec08.rb +2 -0
- data/lib/qrack/protocol/spec09.rb +2 -0
- data/lib/qrack/qrack08.rb +7 -10
- data/lib/qrack/qrack09.rb +7 -10
- data/lib/qrack/queue.rb +27 -40
- data/lib/qrack/subscription.rb +102 -101
- data/lib/qrack/transport/buffer08.rb +266 -264
- data/lib/qrack/transport/buffer09.rb +268 -264
- data/lib/qrack/transport/frame08.rb +13 -11
- data/lib/qrack/transport/frame09.rb +9 -7
- data/spec/spec_08/bunny_spec.rb +48 -45
- data/spec/spec_08/connection_spec.rb +10 -7
- data/spec/spec_08/exchange_spec.rb +145 -143
- data/spec/spec_08/queue_spec.rb +161 -161
- data/spec/spec_09/bunny_spec.rb +46 -44
- data/spec/spec_09/connection_spec.rb +15 -8
- data/spec/spec_09/exchange_spec.rb +147 -145
- data/spec/spec_09/queue_spec.rb +182 -184
- metadata +60 -41
- data/README.rdoc +0 -66
data/lib/bunny.rb
CHANGED
@@ -1,48 +1,59 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
require "socket"
|
4
|
+
require "thread"
|
5
|
+
require "timeout"
|
6
|
+
require "logger"
|
7
7
|
|
8
|
-
require "bunny/version"
|
8
|
+
require File.expand_path("../bunny/version", __FILE__)
|
9
|
+
# if we don't require the version file the same way as in the gemspec,
|
10
|
+
# the version file will be loaded twice. and we hate warnings.
|
9
11
|
|
10
12
|
module Bunny
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
14
|
+
class ConnectionError < StandardError; end
|
15
|
+
class ForcedChannelCloseError < StandardError; end
|
16
|
+
class ForcedConnectionCloseError < StandardError; end
|
17
|
+
class MessageError < StandardError; end
|
18
|
+
class ProtocolError < StandardError; end
|
19
|
+
class ServerDownError < StandardError; end
|
20
|
+
class UnsubscribeError < StandardError; end
|
21
|
+
class AcknowledgementError < StandardError; end
|
22
|
+
|
23
|
+
# Returns the Bunny version number
|
24
|
+
|
25
|
+
def self.version
|
26
|
+
VERSION
|
27
|
+
end
|
28
|
+
|
29
|
+
# Print deprecation warning.
|
30
|
+
def self.deprecation_warning(method, version)
|
31
|
+
warn "~ #{method} will be removed in Bunny #{version}."
|
32
|
+
end
|
33
|
+
|
34
|
+
# Instantiates new Bunny::Client
|
35
|
+
|
36
|
+
def self.new(connection_string_or_opts = Hash.new, opts = Hash.new)
|
37
|
+
# Set up Bunny according to AMQP spec version required
|
38
|
+
if connection_string_or_opts.respond_to?(:keys) && opts.empty?
|
39
|
+
opts = connection_string_or_opts
|
40
|
+
end
|
41
|
+
|
42
|
+
spec_version = opts[:spec] || '08'
|
43
|
+
|
44
|
+
# Return client
|
45
|
+
setup(spec_version, connection_string_or_opts, opts)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Runs a code block using a short-lived connection
|
38
49
|
|
39
50
|
def self.run(opts = {}, &block)
|
40
51
|
raise ArgumentError, 'Bunny#run requires a block' unless block
|
41
52
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
53
|
+
# Set up Bunny according to AMQP spec version required
|
54
|
+
spec_version = opts[:spec] || '08'
|
55
|
+
client = setup(spec_version, opts)
|
56
|
+
|
46
57
|
begin
|
47
58
|
client.start
|
48
59
|
block.call(client)
|
@@ -50,38 +61,49 @@ module Bunny
|
|
50
61
|
client.stop
|
51
62
|
end
|
52
63
|
|
53
|
-
|
54
|
-
|
64
|
+
# Return success
|
65
|
+
:run_ok
|
55
66
|
end
|
56
67
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
68
|
+
Timer = if RUBY_VERSION < "1.9"
|
69
|
+
begin
|
70
|
+
require 'system_timer'
|
71
|
+
SystemTimer
|
72
|
+
rescue LoadError
|
73
|
+
Timeout
|
74
|
+
end
|
75
|
+
else
|
76
|
+
Timeout
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def self.setup(version, *args)
|
82
|
+
if version == '08'
|
83
|
+
# AMQP 0-8 specification
|
84
|
+
require 'qrack/qrack08'
|
85
|
+
require 'bunny/client08'
|
86
|
+
require 'bunny/exchange08'
|
87
|
+
require 'bunny/queue08'
|
88
|
+
require 'bunny/channel08'
|
89
|
+
require 'bunny/subscription08'
|
90
|
+
|
91
|
+
client = Bunny::Client.new(*args)
|
92
|
+
else
|
93
|
+
# AMQP 0-9-1 specification
|
94
|
+
require 'qrack/qrack09'
|
95
|
+
require 'bunny/client09'
|
96
|
+
require 'bunny/exchange09'
|
97
|
+
require 'bunny/queue09'
|
98
|
+
require 'bunny/channel09'
|
99
|
+
require 'bunny/subscription09'
|
100
|
+
|
101
|
+
client = Bunny::Client09.new(*args)
|
102
|
+
end
|
103
|
+
|
104
|
+
include Qrack
|
83
105
|
|
84
106
|
client
|
85
|
-
|
107
|
+
end
|
86
108
|
|
87
|
-
end
|
109
|
+
end
|
data/lib/bunny/channel08.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Bunny
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
4
|
+
class Channel < Qrack::Channel
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def open
|
11
|
+
client.channel = self
|
12
|
+
client.send_frame(Qrack::Protocol::Channel::Open.new)
|
13
|
+
|
14
|
+
method = client.next_method
|
15
|
+
|
16
|
+
client.check_response(method, Qrack::Protocol::Channel::OpenOk, "Cannot open channel #{number}")
|
17
|
+
|
18
|
+
@active = true
|
19
|
+
:open_ok
|
20
|
+
end
|
21
|
+
|
22
|
+
def close
|
23
|
+
client.channel = self
|
24
|
+
client.send_frame(Qrack::Protocol::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0))
|
25
|
+
|
26
|
+
method = client.next_method
|
27
|
+
|
28
|
+
client.check_response(method, Qrack::Protocol::Channel::CloseOk, "Error closing channel #{number}")
|
29
|
+
|
30
|
+
@active = false
|
31
|
+
:close_ok
|
32
|
+
end
|
33
|
+
|
34
|
+
def open?
|
35
|
+
active
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/bunny/channel09.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Bunny
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
class Channel09 < Qrack::Channel
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def open
|
11
|
+
client.channel = self
|
12
|
+
client.send_frame(Qrack::Protocol09::Channel::Open.new)
|
13
|
+
|
12
14
|
method = client.next_method
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
15
|
+
|
16
|
+
client.check_response(method, Qrack::Protocol09::Channel::OpenOk, "Cannot open channel #{number}")
|
17
|
+
|
18
|
+
@active = true
|
19
|
+
:open_ok
|
20
|
+
end
|
21
|
+
|
22
|
+
def close
|
23
|
+
client.channel = self
|
24
|
+
client.send_frame(Qrack::Protocol09::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0))
|
25
|
+
|
26
|
+
method = client.next_method
|
27
|
+
|
28
|
+
client.check_response(method, Qrack::Protocol09::Channel::CloseOk, "Error closing channel #{number}")
|
29
|
+
|
30
|
+
@active = false
|
31
|
+
:close_ok
|
32
|
+
end
|
33
|
+
|
34
|
+
def open?
|
35
|
+
active
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/bunny/client08.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Bunny
|
2
|
-
|
4
|
+
|
3
5
|
=begin rdoc
|
4
6
|
|
5
7
|
=== DESCRIPTION:
|
@@ -9,8 +11,8 @@ The Client class provides the major Bunny API methods.
|
|
9
11
|
=end
|
10
12
|
|
11
13
|
class Client < Qrack::Client
|
12
|
-
|
13
|
-
|
14
|
+
|
15
|
+
attr_accessor :ticket
|
14
16
|
|
15
17
|
=begin rdoc
|
16
18
|
|
@@ -46,10 +48,10 @@ Sets up a Bunny::Client object ready for connection to a broker/server. _Client_
|
|
46
48
|
|
47
49
|
=end
|
48
50
|
|
49
|
-
def initialize(opts =
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def initialize(connection_string_or_opts = Hash.new, opts = Hash.new)
|
52
|
+
super
|
53
|
+
@spec = '0-8'
|
54
|
+
@port = opts[:port] || (opts[:ssl] ? Qrack::Protocol::SSL_PORT : Qrack::Protocol::PORT)
|
53
55
|
@insist = opts[:insist]
|
54
56
|
end
|
55
57
|
|
@@ -61,51 +63,46 @@ Checks response from AMQP methods and takes appropriate action
|
|
61
63
|
|
62
64
|
=end
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def close_connection
|
89
|
-
# Set client channel to zero
|
66
|
+
def check_response(received_method, expected_method, err_msg, err_class = Bunny::ProtocolError)
|
67
|
+
case
|
68
|
+
when received_method.is_a?(Qrack::Protocol::Connection::Close)
|
69
|
+
# Clean up the socket
|
70
|
+
close_socket
|
71
|
+
|
72
|
+
raise Bunny::ForcedConnectionCloseError, "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
|
73
|
+
|
74
|
+
when received_method.is_a?(Qrack::Protocol::Channel::Close)
|
75
|
+
# Clean up the channel
|
76
|
+
channel.active = false
|
77
|
+
|
78
|
+
raise Bunny::ForcedChannelCloseError, "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
|
79
|
+
|
80
|
+
when !received_method.is_a?(expected_method)
|
81
|
+
raise err_class, err_msg
|
82
|
+
|
83
|
+
else
|
84
|
+
:response_ok
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def close_connection
|
89
|
+
# Set client channel to zero
|
90
90
|
switch_channel(0)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
check_response(method, Qrack::Protocol::Connection::CloseOk, "Error closing connection")
|
99
|
-
|
91
|
+
|
92
|
+
send_frame(Qrack::Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0))
|
93
|
+
|
94
|
+
method = next_method
|
95
|
+
|
96
|
+
check_response(method, Qrack::Protocol::Connection::CloseOk, "Error closing connection")
|
100
97
|
end
|
101
98
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
99
|
+
def create_channel
|
100
|
+
channels.each do |c|
|
101
|
+
return c if (!c.open? and c.number != 0)
|
102
|
+
end
|
103
|
+
# If no channel to re-use instantiate new one
|
104
|
+
Bunny::Channel.new(self)
|
105
|
+
end
|
109
106
|
|
110
107
|
=begin rdoc
|
111
108
|
|
@@ -133,92 +130,82 @@ Exchange
|
|
133
130
|
|
134
131
|
=end
|
135
132
|
|
136
|
-
|
133
|
+
def exchange(name, opts = {})
|
137
134
|
exchanges[name] || Bunny::Exchange.new(self, name, opts)
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
135
|
+
end
|
136
|
+
|
137
|
+
def init_connection
|
138
|
+
write(Qrack::Protocol::HEADER)
|
142
139
|
write([1, 1, Qrack::Protocol::VERSION_MAJOR, Qrack::Protocol::VERSION_MINOR].pack('C4'))
|
143
140
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
141
|
+
frame = next_frame
|
142
|
+
if frame.nil? or !frame.payload.is_a?(Qrack::Protocol::Connection::Start)
|
143
|
+
raise Bunny::ProtocolError, 'Connection initiation failed'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def next_frame(opts = {})
|
151
148
|
frame = nil
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
149
|
+
|
150
|
+
case
|
151
|
+
when channel.frame_buffer.size > 0
|
152
|
+
frame = channel.frame_buffer.shift
|
153
|
+
when (timeout = opts[:timeout]) && timeout > 0
|
154
|
+
Bunny::Timer::timeout(timeout, Qrack::ClientTimeout) do
|
155
|
+
frame = Qrack::Transport::Frame.parse(buffer)
|
156
|
+
end
|
157
|
+
else
|
158
|
+
frame = Qrack::Transport::Frame.parse(buffer)
|
159
|
+
end
|
160
|
+
|
161
|
+
@logger.info("received") { frame } if @logging
|
162
|
+
|
163
|
+
raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)
|
164
|
+
|
165
|
+
# Monitor server activity and discard heartbeats
|
166
|
+
@message_in = true
|
167
|
+
|
168
|
+
case
|
169
|
+
when frame.is_a?(Qrack::Transport::Heartbeat)
|
170
|
+
next_frame(opts)
|
171
|
+
when frame.nil?
|
172
|
+
frame
|
173
|
+
when ((frame.channel != channel.number) and (frame.channel != 0))
|
174
|
+
channel.frame_buffer << frame
|
175
|
+
next_frame(opts)
|
176
|
+
else
|
177
|
+
frame
|
162
178
|
end
|
163
|
-
|
164
|
-
@logger.info("received") { frame } if @logging
|
165
|
-
|
166
|
-
raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)
|
167
|
-
|
168
|
-
# Monitor server activity and discard heartbeats
|
169
|
-
@message_in = true
|
170
|
-
|
171
|
-
case
|
172
|
-
when frame.is_a?(Qrack::Transport::Heartbeat)
|
173
|
-
next_frame(opts)
|
174
|
-
when frame.nil?
|
175
|
-
frame
|
176
|
-
when ((frame.channel != channel.number) and (frame.channel != 0))
|
177
|
-
channel.frame_buffer << frame
|
178
|
-
next_frame(opts)
|
179
|
-
else
|
180
|
-
frame
|
181
|
-
end
|
182
|
-
|
183
179
|
end
|
184
180
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
'AMQPLAIN',
|
190
|
-
{:LOGIN => @user, :PASSWORD => @pass},
|
191
|
-
'en_US'
|
192
|
-
)
|
193
|
-
)
|
181
|
+
def open_connection
|
182
|
+
client_opts = { :platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/ruby-amqp/bunny', :version => VERSION }
|
183
|
+
|
184
|
+
send_frame(Qrack::Protocol::Connection::StartOk.new(client_opts, 'AMQPLAIN', {:LOGIN => @user, :PASSWORD => @pass}, 'en_US'))
|
194
185
|
|
195
186
|
frame = next_frame
|
196
|
-
|
197
|
-
|
198
|
-
|
187
|
+
raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
|
188
|
+
|
189
|
+
method = frame.payload
|
199
190
|
|
200
191
|
if method.is_a?(Qrack::Protocol::Connection::Tune)
|
201
|
-
send_frame(
|
202
|
-
Qrack::Protocol::Connection::TuneOk.new( :channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat)
|
203
|
-
)
|
192
|
+
send_frame(Qrack::Protocol::Connection::TuneOk.new( :channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat))
|
204
193
|
end
|
205
194
|
|
206
|
-
send_frame(
|
207
|
-
Qrack::Protocol::Connection::Open.new(:virtual_host => @vhost, :capabilities => '', :insist => @insist)
|
208
|
-
)
|
195
|
+
send_frame(Qrack::Protocol::Connection::Open.new(:virtual_host => @vhost, :capabilities => '', :insist => @insist))
|
209
196
|
|
210
197
|
case method = next_method
|
211
198
|
when Qrack::Protocol::Connection::OpenOk
|
212
199
|
:ok
|
213
200
|
when Qrack::Protocol::Connection::Redirect
|
214
|
-
|
215
|
-
|
201
|
+
raise Bunny::ConnectionError, "Cannot connect to the specified server - host: #{@host}, port: #{@port}" if @insist
|
202
|
+
|
216
203
|
@host, @port = method.host.split(':')
|
217
204
|
close_socket
|
218
205
|
else
|
219
206
|
raise Bunny::ProtocolError, 'Cannot open connection'
|
220
207
|
end
|
221
|
-
|
208
|
+
end
|
222
209
|
|
223
210
|
=begin rdoc
|
224
211
|
|
@@ -252,15 +239,12 @@ true, they are applied to the entire connection.
|
|
252
239
|
|
253
240
|
=end
|
254
241
|
|
255
|
-
|
242
|
+
def qos(opts = {})
|
243
|
+
send_frame(Qrack::Protocol::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts)))
|
256
244
|
|
257
|
-
|
258
|
-
Qrack::Protocol::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts))
|
259
|
-
)
|
245
|
+
method = next_method
|
260
246
|
|
261
|
-
|
262
|
-
|
263
|
-
check_response(method, Qrack::Protocol::Basic::QosOk, "Error specifying Quality of Service")
|
247
|
+
check_response(method, Qrack::Protocol::Basic::QosOk, "Error specifying Quality of Service")
|
264
248
|
|
265
249
|
# return confirmation
|
266
250
|
:qos_ok
|
@@ -280,7 +264,7 @@ occurs a _Bunny_::_ProtocolError_ is raised.
|
|
280
264
|
* <tt>:passive => true or false (_default_)</tt> - If set to _true_, the server will not create
|
281
265
|
the queue. The client can use this to check whether a queue exists without modifying the server
|
282
266
|
state.
|
283
|
-
* <tt>:durable => true or false (_default_)</tt> -
|
267
|
+
* <tt>:durable => true or false (_default_)</tt> - If set to _true_ when creating a new queue, the
|
284
268
|
queue will be marked as durable. Durable queues remain active when a server restarts. Non-durable
|
285
269
|
queues (transient queues) are purged if/when a server restarts. Note that durable queues do not
|
286
270
|
necessarily hold persistent messages, although it does not make sense to send persistent messages
|
@@ -288,8 +272,8 @@ occurs a _Bunny_::_ProtocolError_ is raised.
|
|
288
272
|
* <tt>:exclusive => true or false (_default_)</tt> - If set to _true_, requests an exclusive queue.
|
289
273
|
Exclusive queues may only be consumed from by the current connection. Setting the 'exclusive'
|
290
274
|
flag always implies 'auto-delete'.
|
291
|
-
* <tt>:auto_delete => true or false (_default_)</tt> -
|
292
|
-
when all consumers have finished
|
275
|
+
* <tt>:auto_delete => true or false (_default_)</tt> - If set to _true_, the queue is deleted
|
276
|
+
when all consumers have finished using it. Last consumer can be cancelled either explicitly
|
293
277
|
or because its channel is closed. If there has never been a consumer on the queue, it is not
|
294
278
|
deleted.
|
295
279
|
* <tt>:nowait => true or false (_default_)</tt> - Ignored by Bunny, always _false_.
|
@@ -299,8 +283,8 @@ occurs a _Bunny_::_ProtocolError_ is raised.
|
|
299
283
|
Queue
|
300
284
|
|
301
285
|
=end
|
302
|
-
|
303
|
-
|
286
|
+
|
287
|
+
def queue(name = nil, opts = {})
|
304
288
|
if name.is_a?(Hash)
|
305
289
|
opts = name
|
306
290
|
name = nil
|
@@ -308,7 +292,7 @@ Queue
|
|
308
292
|
|
309
293
|
# Queue is responsible for placing itself in the list of queues
|
310
294
|
queues[name] || Bunny::Queue.new(self, name, opts)
|
311
|
-
|
295
|
+
end
|
312
296
|
|
313
297
|
=begin rdoc
|
314
298
|
|
@@ -325,27 +309,21 @@ the message, potentially then delivering it to an alternative subscriber.
|
|
325
309
|
|
326
310
|
=end
|
327
311
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
Qrack::Protocol::Basic::Recover.new({ :requeue => false }.merge(opts))
|
332
|
-
)
|
312
|
+
def recover(opts = {})
|
313
|
+
send_frame(Qrack::Protocol::Basic::Recover.new({ :requeue => false }.merge(opts)))
|
314
|
+
end
|
333
315
|
|
334
|
-
|
335
|
-
|
336
|
-
def request_access
|
337
|
-
send_frame(
|
338
|
-
Qrack::Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true)
|
339
|
-
)
|
316
|
+
def request_access
|
317
|
+
send_frame(Qrack::Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true))
|
340
318
|
|
341
319
|
method = next_method
|
342
|
-
|
343
|
-
|
344
|
-
|
320
|
+
|
321
|
+
check_response(method, Qrack::Protocol::Access::RequestOk, "Access denied")
|
322
|
+
|
345
323
|
self.ticket = method.ticket
|
346
|
-
|
347
|
-
|
348
|
-
|
324
|
+
end
|
325
|
+
|
326
|
+
def send_frame(*args)
|
349
327
|
args.each do |data|
|
350
328
|
data.ticket = ticket if ticket and data.respond_to?(:ticket=)
|
351
329
|
data = data.to_frame(channel.number) unless data.is_a?(Qrack::Transport::Frame)
|
@@ -354,21 +332,21 @@ the message, potentially then delivering it to an alternative subscriber.
|
|
354
332
|
@logger.info("send") { data } if @logging
|
355
333
|
write(data.to_s)
|
356
334
|
|
357
|
-
|
358
|
-
|
335
|
+
# Monitor client activity for heartbeat purposes
|
336
|
+
@message_out = true
|
359
337
|
end
|
360
338
|
|
361
339
|
nil
|
362
340
|
end
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
341
|
+
|
342
|
+
def send_heartbeat
|
343
|
+
# Create a new heartbeat frame
|
344
|
+
hb = Qrack::Transport::Heartbeat.new('')
|
345
|
+
# Channel 0 must be used
|
346
|
+
switch_channel(0) if @channel.number > 0
|
347
|
+
# Send the heartbeat to server
|
348
|
+
send_frame(hb)
|
349
|
+
end
|
372
350
|
|
373
351
|
=begin rdoc
|
374
352
|
|
@@ -382,36 +360,36 @@ _Bunny_::_ProtocolError_ is raised. If successful, _Client_._status_ is set to <
|
|
382
360
|
<tt>:connected</tt> if successful.
|
383
361
|
|
384
362
|
=end
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
363
|
+
|
364
|
+
def start_session
|
365
|
+
@connecting = true
|
366
|
+
|
389
367
|
loop do
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
368
|
+
# Create/get socket
|
369
|
+
socket
|
370
|
+
|
371
|
+
# Initiate connection
|
372
|
+
init_connection
|
373
|
+
|
374
|
+
# Open connection
|
375
|
+
break if open_connection == :ok
|
398
376
|
end
|
399
377
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
378
|
+
# Open another channel because channel zero is used for specific purposes
|
379
|
+
c = create_channel()
|
380
|
+
c.open
|
381
|
+
|
382
|
+
# Get access ticket
|
383
|
+
request_access
|
384
|
+
|
385
|
+
@connecting = false
|
386
|
+
|
387
|
+
# return status
|
388
|
+
@status = :connected
|
411
389
|
end
|
412
390
|
|
413
|
-
|
414
|
-
|
391
|
+
alias start start_session
|
392
|
+
|
415
393
|
=begin rdoc
|
416
394
|
|
417
395
|
=== DESCRIPTION:
|
@@ -425,17 +403,17 @@ after a commit.
|
|
425
403
|
|
426
404
|
=end
|
427
405
|
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
406
|
+
def tx_commit
|
407
|
+
send_frame(Qrack::Protocol::Tx::Commit.new())
|
408
|
+
|
409
|
+
method = next_method
|
410
|
+
|
411
|
+
check_response(method, Qrack::Protocol::Tx::CommitOk, "Error commiting transaction")
|
412
|
+
|
413
|
+
# return confirmation
|
414
|
+
:commit_ok
|
415
|
+
end
|
416
|
+
|
439
417
|
=begin rdoc
|
440
418
|
|
441
419
|
=== DESCRIPTION:
|
@@ -449,16 +427,16 @@ after a rollback.
|
|
449
427
|
|
450
428
|
=end
|
451
429
|
|
452
|
-
|
453
|
-
|
430
|
+
def tx_rollback
|
431
|
+
send_frame(Qrack::Protocol::Tx::Rollback.new())
|
454
432
|
|
455
|
-
|
456
|
-
|
457
|
-
|
433
|
+
method = next_method
|
434
|
+
|
435
|
+
check_response(method, Qrack::Protocol::Tx::RollbackOk, "Error rolling back transaction")
|
458
436
|
|
459
|
-
|
460
|
-
|
461
|
-
|
437
|
+
# return confirmation
|
438
|
+
:rollback_ok
|
439
|
+
end
|
462
440
|
|
463
441
|
=begin rdoc
|
464
442
|
|
@@ -473,18 +451,18 @@ using the Commit or Rollback methods.
|
|
473
451
|
|
474
452
|
=end
|
475
453
|
|
476
|
-
|
477
|
-
|
454
|
+
def tx_select
|
455
|
+
send_frame(Qrack::Protocol::Tx::Select.new())
|
478
456
|
|
479
|
-
|
480
|
-
|
481
|
-
|
457
|
+
method = next_method
|
458
|
+
|
459
|
+
check_response(method, Qrack::Protocol::Tx::SelectOk, "Error initiating transactions for current channel")
|
482
460
|
|
483
|
-
|
484
|
-
|
485
|
-
|
461
|
+
# return confirmation
|
462
|
+
:select_ok
|
463
|
+
end
|
486
464
|
|
487
|
-
|
465
|
+
private
|
488
466
|
|
489
467
|
def buffer
|
490
468
|
@buffer ||= Qrack::Transport::Buffer.new(self)
|