qpid_messaging 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/LICENSE +234 -0
  2. data/README.rdoc +46 -0
  3. data/Rakefile +87 -0
  4. data/TODO +7 -0
  5. data/examples/client.rb +50 -0
  6. data/examples/drain.rb +111 -0
  7. data/examples/hello_world.rb +49 -0
  8. data/examples/map_receiver.rb +63 -0
  9. data/examples/map_sender.rb +52 -0
  10. data/examples/server.rb +51 -0
  11. data/examples/spout.rb +126 -0
  12. data/ext/cqpid/cqpid.cpp +9903 -0
  13. data/ext/cqpid/extconf.rb +73 -0
  14. data/features/closing_a_connection.feature +13 -0
  15. data/features/closing_a_session.feature +13 -0
  16. data/features/connecting_to_a_broker.feature +13 -0
  17. data/features/creating_a_receiver.feature +29 -0
  18. data/features/creating_a_sender.feature +25 -0
  19. data/features/creating_a_session.feature +12 -0
  20. data/features/getting_the_connections_authenticated_username.feature +8 -0
  21. data/features/receiving_a_message.feature +28 -0
  22. data/features/sending_a_message.feature +21 -0
  23. data/features/session_returns_its_connection.feature +12 -0
  24. data/features/sessions_have_names.feature +8 -0
  25. data/features/step_definitions/address_steps.rb +24 -0
  26. data/features/step_definitions/connection_steps.rb +93 -0
  27. data/features/step_definitions/receiver_steps.rb +61 -0
  28. data/features/step_definitions/sender_steps.rb +34 -0
  29. data/features/step_definitions/session_steps.rb +99 -0
  30. data/features/support/env.rb +22 -0
  31. data/lib/qpid_messaging.rb +30 -0
  32. data/lib/qpid_messaging/address.rb +187 -0
  33. data/lib/qpid_messaging/connection.rb +162 -0
  34. data/lib/qpid_messaging/duration.rb +95 -0
  35. data/lib/qpid_messaging/encoding.rb +61 -0
  36. data/lib/qpid_messaging/errors.rb +33 -0
  37. data/lib/qpid_messaging/message.rb +368 -0
  38. data/lib/qpid_messaging/receiver.rb +184 -0
  39. data/lib/qpid_messaging/sender.rb +152 -0
  40. data/lib/qpid_messaging/session.rb +269 -0
  41. data/lib/qpid_messaging/version.rb +33 -0
  42. data/spec/qpid/address_spec.rb +87 -0
  43. data/spec/qpid/connection_spec.rb +191 -0
  44. data/spec/qpid/duration_spec.rb +56 -0
  45. data/spec/qpid/encoding_spec.rb +63 -0
  46. data/spec/qpid/message_spec.rb +292 -0
  47. data/spec/qpid/receiver_spec.rb +170 -0
  48. data/spec/qpid/sender_spec.rb +135 -0
  49. data/spec/qpid/session_spec.rb +353 -0
  50. data/spec/spec_helper.rb +20 -0
  51. metadata +106 -0
@@ -0,0 +1,34 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ Given /^the message "([^"]*)" is sent$/ do |content|
21
+ @sender.send Qpid::Messaging::Message.new :content => "#{content}"
22
+ end
23
+
24
+ Then /^sending the message "([^"]*)" should raise an error$/ do |content|
25
+ lambda {
26
+ steps %Q{
27
+ Then sending the message "#{content}" succeeds
28
+ }
29
+ }.should raise_error
30
+ end
31
+
32
+ Then /^sending the message "([^"]*)" succeeds$/ do |content|
33
+ @sender.send Qpid::Messaging::Message.new :content => "#{content}"
34
+ end
@@ -0,0 +1,99 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ Given /^a closed session/ do
21
+ steps %Q{
22
+ Given an open connection
23
+ Then creating a session works
24
+ }
25
+ @connection.close
26
+ end
27
+
28
+ Then /^creating a sender with "([^"]*)" raises an exception$/ do |address|
29
+ lambda {
30
+ steps %Q{
31
+ @sender = @session.create_sender "#{address}"
32
+ }
33
+ }.should raise_error
34
+ end
35
+
36
+ Then /^creating a receiver with "([^"]*)" raises an exception$/ do |address|
37
+ lambda {
38
+ steps %Q{
39
+ @sender = @session.create_sender "#{address}"
40
+ }
41
+ }.should raise_error
42
+ end
43
+
44
+ Given /^an open session with a closed connection$/ do
45
+ steps %Q{
46
+ Given an open connection
47
+ Then creating a session works
48
+ }
49
+ @session.connection.close
50
+ end
51
+
52
+ Given /^an open session$/ do
53
+ steps %Q{
54
+ Given an open connection
55
+ Then creating a session works
56
+ }
57
+ end
58
+
59
+ Given /^the session is closed$/ do
60
+ @session.close
61
+ end
62
+
63
+ Then /^creating a sender with "([^"]*)" succeeds$/ do |address|
64
+ @sender = @session.create_sender "#{address}"
65
+ @sender.should_not be_nil
66
+ end
67
+
68
+ Then /^creating a sender with an Address succeeds$/ do
69
+ @sender = @session.create_receiver @address
70
+ @sender.should_not be_nil
71
+ end
72
+
73
+ Then /^creating a receiver for a nonexistent queue raises an exception$/ do
74
+ lambda {
75
+ steps %Q{
76
+ Then creating a receiver with "queue-#{Time.new.to_i}" succeeds
77
+ }
78
+ }.should raise_error
79
+ end
80
+
81
+ Then /^creating a receiver with "([^"]*)" succeeds$/ do |address|
82
+ @receiver = @session.create_receiver "#{address}"
83
+ @receiver.should_not be_nil
84
+ end
85
+
86
+ Then /^creating a receiver with an Address succeeds$/ do
87
+ @receiver = @session.create_receiver @address
88
+ @receiver.should_not be_nil
89
+ end
90
+
91
+ Then /^closing the session does not raise an error$/ do
92
+ lambda {
93
+ @session.close
94
+ }.should_not raise_error
95
+ end
96
+
97
+ Then /^the connection for the session is in the (open|closed) state$/ do |state|
98
+ @session.connection.open?.should == false if state == "closed"
99
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../../lib")
21
+
22
+ require 'qpid_messaging'
@@ -0,0 +1,30 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require 'qpid_messaging/version'
21
+ require 'qpid_messaging/errors'
22
+ require 'qpid_messaging/duration'
23
+ require 'qpid_messaging/address'
24
+ require 'qpid_messaging/encoding'
25
+ require 'qpid_messaging/message'
26
+ require 'qpid_messaging/sender'
27
+ require 'qpid_messaging/receiver'
28
+ require 'qpid_messaging/session'
29
+ require 'qpid_messaging/connection'
30
+
@@ -0,0 +1,187 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require 'cqpid'
21
+
22
+ module Qpid
23
+
24
+ module Messaging
25
+
26
+ # Address represents an address to which messages can be sent or from
27
+ # which they can be received.
28
+ #
29
+ # An Address can be described using the following pattern:
30
+ #
31
+ # <address> [ / <subject> ] ; [ { <key> : <value> , ... } ]
32
+ #
33
+ # where *address* is a simple name and *subject* is a subject or subject
34
+ # pattern.
35
+ #
36
+ # The options, enclosed in curly braces, are key:value pairs delimited by
37
+ # a comma. The values can be nested maps also enclosed in curly braces.
38
+ # Or they can be lists of values, where they are contained within square
39
+ # brackets but still comma delimited, such as:
40
+ #
41
+ # [value1,value2,value3]
42
+ #
43
+ # The following are the list of supported options:
44
+ #
45
+ # [:create]
46
+ # Indicates if the address should be created; values are *always*,
47
+ # *never*, *sender* or *reciever*.
48
+ #
49
+ # [:assert]
50
+ # Indicates whether or not to assert any specified node properties;
51
+ # values are *always*, *never*, *sender* or *receiver*.
52
+ #
53
+ # [:delete]
54
+ # Indicates whether or not to delete the addressed node when a sender
55
+ # or receiver is cancelled; values are *always*, *never*, *sender* or
56
+ # *receiver*.
57
+ #
58
+ # [:node]
59
+ # A nested map describing properties for the addressed node. Properties
60
+ # are *type* (*topic* or *queue*), *durable* (a boolean), *x-declare*
61
+ # (a nested map of amqp 0.10-specific options) and *x-bindings*. (nested
62
+ # list which specifies a queue, exchange or a binding key and arguments.
63
+ #
64
+ # [:link]
65
+ # A nested map through which properties of the link can be specified;
66
+ # properties are *durable*, *reliability*, *x-declare*, *x-subscribe*
67
+ # and *x-bindings*.
68
+ #
69
+ # [:mode]
70
+ # (*For receivers only*) indicates whether the receiver should consume
71
+ # or browse messages; values are *consume* (the default) and *browse*.
72
+ #
73
+ class Address
74
+
75
+ # Creates a new +Address+ object.
76
+ #
77
+ # ==== Options
78
+ #
79
+ # * name - The name for the +Address+.
80
+ # * subject - The subject for the +Address+
81
+ # * :create - See the class documentation.
82
+ # * :assert - See the class documentation.
83
+ # * :delete - See the class documentation.
84
+ # * :node - See the class documentation.
85
+ # * :link - See the class documentation.
86
+ # * :mode - See the class documentation.
87
+ #
88
+ # ==== Examples
89
+ #
90
+ # addr = Qpid::Messaging::Address.new "my-queue"
91
+ # addr = Qpid::Messaging::Address.new "my-queue", "testing", :create => :always
92
+ #
93
+ def initialize(name, subject, options = {}, _type = "", address_impl = nil)
94
+ @address_impl = address_impl || Cqpid::Address.new(name, subject, convert_options(options), _type)
95
+ end
96
+
97
+ def address_impl # :nodoc:
98
+ @address_impl
99
+ end
100
+
101
+ # Returns the name for the +Address+.
102
+ #
103
+ # ==== Examples
104
+ #
105
+ # puts "The address name is #{addr.name}."
106
+ #
107
+ def name; @address_impl.getName; end
108
+
109
+ # Sets the name for the +Address+.
110
+ #
111
+ # ==== Examples
112
+ #
113
+ # addr.name = "my-new-queue"
114
+ #
115
+ def name=(name); @address_impl.setName name; end
116
+
117
+ # Returns the subject for the +Address+.
118
+ #
119
+ # ==== Examples
120
+ #
121
+ # puts "The subject is #{addr.subject}."
122
+ #
123
+ def subject; @address_impl.getSubject; end
124
+
125
+ # Sets the subject for the +Address+.
126
+ #
127
+ # ==== Examples
128
+ #
129
+ # addr.subject = "testing"
130
+ #
131
+ def subject=(subject); @address_impl.setSubject(subject); end
132
+
133
+ # Returns the type for the +Address+.
134
+ #
135
+ # ==== Examples
136
+ #
137
+ # puts "The address is a #{address.address_type}."
138
+ #
139
+ #---
140
+ # We cannot use "type" since that clashes with the Ruby object.type
141
+ # identifier.
142
+ def address_type; @address_impl.getType; end
143
+
144
+ # Sets the type for the +Address+.
145
+ #
146
+ # The type of the address determines how +Sender+ and +Receiver+ objects
147
+ # are constructed for it. If no type is specified then it will be
148
+ # determined by querying the broker.
149
+ #
150
+ # ===== Options
151
+ #
152
+ # * type - the address type
153
+ #
154
+ def address_type=(type); @address_impl.setType(type); end
155
+
156
+ # Returns the options.
157
+ def options; @address_impl.getOptions; end
158
+
159
+ # Sets the options for the address.
160
+ #
161
+ # *NOTE:* See the class documentation for more details on options.
162
+ #
163
+ # ==== Examples
164
+ #
165
+ # addr.options = :create => :always
166
+ #
167
+ def options=(options = {}); @address_impl.setOptions(convert_options(options)); end
168
+
169
+ def to_s # :nodoc:
170
+ @address_impl.str
171
+ end
172
+
173
+ private
174
+
175
+ def convert_options(options)
176
+ result = {}
177
+ options.each_pair {|key, value| result[key.to_s] = value.to_s}
178
+
179
+ return result
180
+ end
181
+
182
+ end
183
+
184
+ end
185
+
186
+ end
187
+
@@ -0,0 +1,162 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ require 'cqpid'
21
+
22
+ module Qpid
23
+
24
+ module Messaging
25
+
26
+ # Establishes a connection to a remote endpoint.
27
+ class Connection
28
+
29
+ attr_reader :options # :nodoc:
30
+
31
+ # Creates a connection object, but does not actually connect to
32
+ # the specified location.
33
+ #
34
+ # ==== Options
35
+ #
36
+ # :url - the URL for the broker (def. +"localhost"+)
37
+ # :options - connection options (def. +{}+)
38
+ #
39
+ # ==== Controlling Reconnect Behavior
40
+ #
41
+ # The following connection options can be used to configure
42
+ # the reconnection behavior for this connection.
43
+ #
44
+ # * :username
45
+ # * :password
46
+ # * :heartbeat
47
+ # * :tcp_nodelay
48
+ # * :sasl_mechanism
49
+ # * :sasl_service
50
+ # * :sasl_min_ssf
51
+ # * :sasl_max_ssf
52
+ # * :transport
53
+ # * :reconnect - +true+ or +false+; indicates wehtehr to attempt reconnections
54
+ # * :reconnect_timeout - the number of seconds to attempt reconnecting
55
+ # * :reconnect_limit - the number of retries before reporting failure
56
+ # * :reconnect_interval_min - initial delay, in seconds, before attempting a reconnection
57
+ # * :reconnect_interval_max - number of seconds to wait before additional reconnect attempts
58
+ # * :reconnect_interval - shorthand for setting both min and max values
59
+ # * :reconnect_urls - a list of alternate URLs to use for reconnection attempts
60
+ #
61
+ # ==== Examples
62
+ #
63
+ # conn = Qpid::Messaging::Connnection.new
64
+ # conn = Qpid::Messaging::Connection.new :url => "amqp:tcp:broker1.domain.com:5672"
65
+ # conn = Qpid::Messaging::Connection.new :options => {:username => "login", :password => "password"}
66
+ #
67
+ def initialize(opts = {})
68
+ @url = opts[:url] || "localhost"
69
+ @options = convert_options(opts[:options] || {})
70
+ @connection_impl = opts[:impl] || Cqpid::Connection.new(@url, @options)
71
+ end
72
+
73
+ def connection_impl # :nodoc:
74
+ @connection_impl
75
+ end
76
+
77
+ # Establishes the connection.
78
+ #
79
+ # ==== Examples
80
+ #
81
+ # conn.open unless conn.open?
82
+ #
83
+ def open
84
+ @connection_impl.open
85
+ end
86
+
87
+ # Reports whether the connection is open.
88
+ #
89
+ # ==== Examples
90
+ #
91
+ # conn.close if conn.open?
92
+ #
93
+ def open?; true && !@connection_impl.nil? && @connection_impl.isOpen; end
94
+
95
+ # Closes the connection.
96
+ def close; @connection_impl.close; end
97
+
98
+ # Creates a new session.
99
+ #
100
+ # ==== Arguments
101
+ #
102
+ # * :name - specifies the name for this session
103
+ # * :transactional - if +true+ then a creates a transaction session (def. +false+)
104
+ #
105
+ # ==== Examples
106
+ #
107
+ # session = conn.create_session :name => "session1"
108
+ # session = conn.create_session :transaction => true
109
+ #
110
+ def create_session(args = {})
111
+ name = args[:name] || ""
112
+ if open?
113
+ if args[:transactional]
114
+ session = @connection_impl.createTransactionalSession name
115
+ else
116
+ session = @connection_impl.createSession name
117
+ end
118
+ return Session.new(self, session)
119
+ else
120
+ raise RuntimeError.new "No connection available."
121
+ end
122
+ end
123
+
124
+ # Returns a session for the specified session name.
125
+ #
126
+ # ==== Examples
127
+ #
128
+ # begin
129
+ # session = conn.session "mysession"
130
+ # rescue SessionNameException => error
131
+ # puts "No such session."
132
+ # end
133
+ #
134
+ def session name
135
+ begin
136
+ session_impl = @connection_impl.getSession name
137
+ Qpid::Messaging::Session.new self, session_impl if session_impl
138
+ rescue
139
+ raise Qpid::Messaging::SessionNameException.new "No such session: #{name}"
140
+ end
141
+ end
142
+
143
+ # Returns the username used to authenticate with the connection.
144
+ def authenticated_username; @connection_impl.getAuthenticatedUsername if open?; end
145
+
146
+ private
147
+
148
+ def convert_options(options)
149
+ result = {}
150
+ unless options.nil? || options.empty?
151
+ options.each_pair {|key, value| result[key.to_s] = value.to_s}
152
+ end
153
+
154
+ return result
155
+ end
156
+
157
+ end
158
+
159
+ end
160
+
161
+ end
162
+