amq-client 0.7.0.alpha25 → 0.7.0.alpha26

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.
@@ -10,7 +10,7 @@ module AMQ
10
10
  #
11
11
  # @see AMQ::Client::Settings.configure
12
12
  def self.default
13
- {
13
+ @default ||= {
14
14
  # server
15
15
  :host => "127.0.0.1",
16
16
  :port => AMQ::Protocol::DEFAULT_PORT,
@@ -37,6 +37,17 @@ module AMQ
37
37
  }
38
38
  end
39
39
 
40
+
41
+ def self.client_properties
42
+ @client_properties ||= {
43
+ :platform => ::RUBY_DESCRIPTION,
44
+ :product => "AMQ Client",
45
+ :information => "http://github.com/ruby-amqp/amq-client",
46
+ :version => AMQ::Client::VERSION
47
+ }
48
+ end
49
+
50
+
40
51
  # Merges given configuration parameters with defaults and returns
41
52
  # the result.
42
53
  #
@@ -1,5 +1,5 @@
1
1
  module AMQ
2
2
  module Client
3
- VERSION = "0.7.0.alpha25"
3
+ VERSION = "0.7.0.alpha26"
4
4
  end
5
5
  end
@@ -7,14 +7,14 @@ describe "AMQ::Client::CoolioClient", "Connection.Close", :nojruby => true do
7
7
 
8
8
  it "should issue a callback and close connection" do
9
9
  coolio do
10
- AMQ::Client::CoolioClient.connect do |client|
11
- @client = client
12
- client.should be_opened
13
- client.close do
10
+ AMQ::Client::CoolioClient.connect do |connection|
11
+ @connection = connection
12
+ connection.should be_opened
13
+ connection.disconnect do
14
14
  done
15
15
  end
16
16
  end
17
17
  end
18
- @client.should be_closed
18
+ @connection.should be_closed
19
19
  end
20
20
  end
@@ -34,12 +34,15 @@ describe "AMQ::Client::CoolioClient", "Connection.Start", :nojruby => true do
34
34
  it "should raise an error" do
35
35
  expect {
36
36
  coolio do
37
- AMQ::Client::CoolioClient.connect(:port => 12938) { }
38
- done(0.5)
37
+ begin
38
+ AMQ::Client::CoolioClient.connect(:port => 12938) { }
39
+ done
40
+ rescue Exception => e
41
+ done(0.5)
42
+ end
39
43
  end
40
44
  }.to raise_error(AMQ::Client::TCPConnectionFailed)
41
45
  end
42
- end
43
- end
44
-
45
- end
46
+ end # context
47
+ end # context
48
+ end # describe
@@ -7,14 +7,14 @@ describe AMQ::Client::EventMachineClient, "Channel.Close" do
7
7
 
8
8
  it "should close the channel" do
9
9
  @events = []
10
- em_amqp_connect do |client|
10
+ em_amqp_connect do |connection|
11
11
  @events << :connect
12
- channel = AMQ::Client::Channel.new(client, 1)
12
+ channel = AMQ::Client::Channel.new(connection, 1)
13
13
  channel.open do
14
14
  @events << :open
15
15
  channel.close do
16
16
  @events << :close
17
- client.disconnect do
17
+ connection.disconnect do
18
18
  @events << :disconnect
19
19
  done
20
20
  end
@@ -23,4 +23,4 @@ describe AMQ::Client::EventMachineClient, "Channel.Close" do
23
23
  end
24
24
  @events.should == [:connect, :open, :close, :disconnect]
25
25
  end
26
- end
26
+ end
@@ -7,14 +7,14 @@ describe AMQ::Client::EventMachineClient, "Connection.Close" do
7
7
 
8
8
  it "should issue a callback and close connection" do
9
9
  em do
10
- AMQ::Client::EventMachineClient.connect do |client|
11
- @client = client
12
- client.should be_opened
13
- client.close do
10
+ AMQ::Client::EventMachineClient.connect do |connection|
11
+ @connection = connection
12
+ connection.should be_opened
13
+ connection.disconnect do
14
14
  done
15
15
  end
16
16
  end
17
17
  end
18
- @client.should be_closed
18
+ @connection.should be_closed
19
19
  end
20
20
  end
@@ -53,15 +53,10 @@ describe AMQ::Client::Entity do
53
53
 
54
54
 
55
55
  it "should pass arguments to the callback" do
56
- subject.define_callback :init, Proc.new { |*args| args.first }
56
+ f = Proc.new { |*args| args.first }
57
+ subject.define_callback :init, f
57
58
 
58
- subject.exec_callback(:init, 1).should eql([1])
59
- end
60
-
61
- it "should pass block to the callback" do
62
- subject.define_callback :init, Proc.new { |*args, &block| block.call }
63
-
64
- subject.exec_callback(:init) { "block" }.should == ["block"]
59
+ subject.exec_callback(:init, 1).should eql([f])
65
60
  end
66
61
  end
67
62
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amq-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: -3702664418
4
+ hash: -3702664424
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
9
  - 0
10
10
  - alpha
11
- - 25
12
- version: 0.7.0.alpha25
11
+ - 26
12
+ version: 0.7.0.alpha26
13
13
  platform: ruby
14
14
  authors:
15
15
  - Jakub Stastny
@@ -20,7 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2011-05-18 00:00:00 Z
23
+ date: 2011-05-22 00:00:00 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: eventmachine
@@ -154,7 +154,6 @@ files:
154
154
  - lib/amq/client/adapters/event_machine.rb
155
155
  - lib/amq/client/callbacks.rb
156
156
  - lib/amq/client/channel.rb
157
- - lib/amq/client/connection.rb
158
157
  - lib/amq/client/entity.rb
159
158
  - lib/amq/client/exceptions.rb
160
159
  - lib/amq/client/exchange.rb
@@ -251,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
250
  requirements: []
252
251
 
253
252
  rubyforge_project: amq-client
254
- rubygems_version: 1.8.2
253
+ rubygems_version: 1.8.3
255
254
  signing_key:
256
255
  specification_version: 3
257
256
  summary: amq-client is a fully-featured, low-level AMQP 0.9.1 client
@@ -1,246 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "amq/client"
4
- require "amq/client/entity"
5
-
6
- module AMQ
7
- module Client
8
- # AMQP connection object handles various connection lifecycle events
9
- # (for example, Connection.Start-Ok, Connection.Tune-Ok and Connection.Close
10
- # methods)
11
- #
12
- # AMQP connection has multiple channels accessible via {Connection#channels} reader.
13
- class Connection
14
-
15
- #
16
- # Behaviors
17
- #
18
-
19
- include Entity
20
- extend ProtocolMethodHandlers
21
-
22
- #
23
- # API
24
- #
25
-
26
- DEFAULT_CLIENT_PROPERTIES = {
27
- :platform => ::RUBY_DESCRIPTION,
28
- :product => "AMQ Client",
29
- :information => "http://github.com/ruby-amqp/amq-client",
30
- :version => AMQ::Client::VERSION
31
- }
32
-
33
-
34
- # Client capabilities
35
- #
36
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.2.1)
37
- attr_accessor :client_properties
38
-
39
- # Server capabilities
40
- #
41
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.1.3)
42
- attr_reader :server_properties
43
-
44
- # Authentication mechanism used.
45
- #
46
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.2)
47
- attr_reader :mechanism
48
-
49
- # Security response data.
50
- #
51
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Sections 1.4.2.2 and 1.4.2.4.1)
52
- attr_reader :response
53
-
54
- # The locale defines the language in which the server will send reply texts.
55
- #
56
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.2)
57
- attr_reader :locale
58
-
59
- # Channels within this connection.
60
- #
61
- # @see http://bit.ly/hw2ELX AMQP 0.9.1 specification (Section 2.2.5)
62
- attr_reader :channels
63
-
64
- # Maximum channel number that the server permits this connection to use.
65
- # Usable channel numbers are in the range 1..channel_max.
66
- # Zero indicates no specified limit.
67
- #
68
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Sections 1.4.2.5.1 and 1.4.2.6.1)
69
- attr_accessor :channel_max
70
-
71
- # Maximum frame size that the server permits this connection to use.
72
- #
73
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Sections 1.4.2.5.2 and 1.4.2.6.2)
74
- attr_accessor :frame_max
75
-
76
- # The delay, in seconds, of the connection heartbeat that the server wants.
77
- # Zero means the server does not want a heartbeat.
78
- #
79
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.5.3)
80
- attr_accessor :heartbeat_interval
81
-
82
- attr_reader :known_hosts
83
-
84
-
85
-
86
- # @api public
87
- def initialize(client, mechanism, response, locale, client_properties = {})
88
- @mechanism = mechanism
89
- @response = response
90
- @locale = locale
91
-
92
- @channels = Hash.new
93
- @client_properties = DEFAULT_CLIENT_PROPERTIES.merge(client_properties)
94
-
95
- reset_state!
96
-
97
- super(client)
98
-
99
- @client.connections.push(self)
100
-
101
- # Default errback.
102
- # You might want to override it, otherwise it'll
103
- # crash your program. It's the expected behaviour
104
- self.define_callback(:close) { |exception| raise(exception) }
105
- end
106
-
107
- # @api public
108
- def settings
109
- @client.settings
110
- end # settings
111
-
112
-
113
-
114
- #
115
- # Connection class methods
116
- #
117
-
118
-
119
- # Sends connection.open to the server.
120
- #
121
- # @api public
122
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.7)
123
- def open(vhost = "/")
124
- @client.send Protocol::Connection::Open.encode(vhost)
125
- end
126
-
127
-
128
- # Sends connection.close to the server.
129
- #
130
- # @api public
131
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.9)
132
- def close(reply_code = 200, reply_text = "Goodbye", class_id = 0, method_id = 0)
133
- @client.send Protocol::Connection::Close.encode(reply_code, reply_text, class_id, method_id)
134
- closing!
135
- end
136
-
137
- # @api public
138
- def reset_state!
139
- end # reset_state!
140
-
141
-
142
-
143
- #
144
- # Implementation
145
- #
146
-
147
-
148
- # Handles Connection.Start.
149
- #
150
- # @api plugin
151
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.1.)
152
- def start_ok(method)
153
- @server_properties = method.server_properties
154
-
155
- # It's not clear whether we should transition to :opening state here
156
- # or in #open but in case authentication fails, it would be strange to have
157
- # @status undefined. So lets do this. MK.
158
- opening!
159
-
160
- @client.send Protocol::Connection::StartOk.encode(@client_properties, @mechanism, @response, @locale)
161
- end
162
-
163
-
164
- # Handles Connection.Open-Ok.
165
- #
166
- # @api plugin
167
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.8.)
168
- def handle_open_ok(method)
169
- @known_hosts = method.known_hosts
170
-
171
- opened!
172
- @client.connection_successful if @client.respond_to?(:connection_successful)
173
- end
174
-
175
- # Handles Connection.Tune-Ok.
176
- #
177
- # @api plugin
178
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.6)
179
- def handle_tune(method)
180
- @channel_max = method.channel_max
181
- @frame_max = method.frame_max
182
- @heartbeat_interval = @client.heartbeat_interval || method.heartbeat
183
-
184
- @client.send Protocol::Connection::TuneOk.encode(@channel_max, [settings[:frame_max], @frame_max].min, @heartbeat_interval)
185
- end # handle_tune(method)
186
-
187
-
188
- # Handles Connection.Close.
189
- #
190
- # @api plugin
191
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.5.2.9)
192
- def handle_close(method)
193
- self.handle_connection_interruption
194
-
195
- closed!
196
- # TODO: use proper exception class, provide protocol class (we know method.class_id and method.method_id) as well!
197
- error = RuntimeError.new(method.reply_text)
198
- self.error(error)
199
- end
200
-
201
- # Handles Connection.Close-Ok.
202
- #
203
- # @api plugin
204
- # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.10)
205
- def handle_close_ok(method)
206
- closed!
207
- @client.disconnection_successful
208
- end # handle_close_ok(method)
209
-
210
- # @api plugin
211
- def handle_connection_interruption
212
- @channels.each { |n, c| c.handle_connection_interruption }
213
- end # handle_connection_interruption
214
-
215
-
216
-
217
- #
218
- # Handlers
219
- #
220
-
221
- self.handle(Protocol::Connection::Start) do |client, frame|
222
- client.connection.start_ok(frame.decode_payload)
223
- end
224
-
225
- self.handle(Protocol::Connection::Tune) do |client, frame|
226
- client.connection.handle_tune(frame.decode_payload)
227
-
228
- client.connection.open(client.settings[:vhost] || "/")
229
- end
230
-
231
- self.handle(Protocol::Connection::OpenOk) do |client, frame|
232
- client.connection.handle_open_ok(frame.decode_payload)
233
- end
234
-
235
- self.handle(Protocol::Connection::Close) do |client, frame|
236
- client.connection.handle_close(frame.decode_payload)
237
- end
238
-
239
- self.handle(Protocol::Connection::CloseOk) do |client, frame|
240
- client.connection.handle_close_ok(frame.decode_payload)
241
- end
242
-
243
-
244
- end # Connection
245
- end # Client
246
- end # AMQ