qpid_messaging 0.16.0

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.
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,73 @@
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
+ # To create the Makefile then you need to specify the location
21
+ # of the Qpid shared libraries using the commandline:
22
+ #
23
+ # $ ruby extconf.rb --with-qpid-lib=[path to libraries]
24
+ #
25
+
26
+ require 'mkmf'
27
+
28
+ # Setup the build environment.
29
+ $CFLAGS = "-fPIC -fno-inline -x c++"
30
+
31
+ REQUIRED_LIBRARIES = [
32
+ 'qpidclient',
33
+ 'qpidcommon',
34
+ 'qpidmessaging',
35
+ 'qpidtypes'
36
+ ]
37
+
38
+ REQUIRED_HEADERS = [
39
+ 'qpid/messaging/Address.h',
40
+ 'qpid/messaging/Connection.h',
41
+ 'qpid/messaging/Duration.h',
42
+ 'qpid/messaging/exceptions.h',
43
+ 'qpid/messaging/FailoverUpdates.h',
44
+ 'qpid/messaging/Handle.h',
45
+ 'qpid/messaging/ImportExport.h',
46
+ 'qpid/messaging/Message.h',
47
+ 'qpid/messaging/Receiver.h',
48
+ 'qpid/messaging/Sender.h',
49
+ 'qpid/messaging/Session.h'
50
+ ]
51
+
52
+ dir_config('qpid')
53
+
54
+ def abort_build filetype, filename
55
+ abort "Missing required #{filetype}: #{filename}"
56
+ end
57
+
58
+ def require_library lib
59
+ abort_build "library", lib unless have_library lib
60
+ end
61
+
62
+ def require_header header
63
+ abort_build "header", header unless have_header header
64
+ end
65
+
66
+ have_library('stdc++')
67
+
68
+ REQUIRED_LIBRARIES.each {|library| require_library library}
69
+
70
+ REQUIRED_HEADERS.each {|header| require_header header}
71
+
72
+ create_makefile('cqpid')
73
+
@@ -0,0 +1,13 @@
1
+ Feature: Closing an open connection
2
+ When working with a broker
3
+ As a producer or consumer
4
+ I want to close a connection
5
+
6
+ Scenario: The connection is already closed
7
+ Given a closed connection
8
+ Then calling close does not raise an exception
9
+
10
+ Scenario: The connection is open
11
+ Given an open connection
12
+ And the connection is closed
13
+ Then the connection is in the closed state
@@ -0,0 +1,13 @@
1
+ Feature: Closing an open session
2
+ While working with a session
3
+ As a producer or consumer
4
+ I want to close the session
5
+
6
+ Scenario: The connection has already been closed
7
+ Given an open session with a closed connection
8
+ Then closing the session does not raise an error
9
+
10
+ Scenario: Closing an active session
11
+ Given an open session
12
+ Then closing the session does not raise an error
13
+ And the connection is in the open state
@@ -0,0 +1,13 @@
1
+ Feature: Connecting to a broker
2
+ In order to interaction on an AMQP network
3
+ As a producer or consumer
4
+ I want to connect to a broker
5
+
6
+ Scenario: Connections are closed by default
7
+ Given a new connection
8
+ Then the connection is in the closed state
9
+
10
+ Scenario: Opening a connection
11
+ Given a new connection
12
+ And the connection is opened
13
+ Then the connection is in the open state
@@ -0,0 +1,29 @@
1
+ Feature: Creating a receiver
2
+ When working with a messaging environment
3
+ As a consumer
4
+ I want to create a Receiver for consuming messages
5
+
6
+ Scenario: The session is closed
7
+ Given a closed session
8
+ Then creating a receiver with "my-queue" raises an exception
9
+
10
+ Scenario: The connection is closed
11
+ Given an open session with a closed connection
12
+ Then creating a receiver with "my-queue" raises an exception
13
+
14
+ Scenario: The address is malformed
15
+ Given an open session
16
+ Then creating a receiver with "my-queue;{foo:bar}" raises an exception
17
+
18
+ Scenario: The address string is valid but the queue does not exist
19
+ Given an open session
20
+ Then creating a receiver for a nonexistent queue raises an exception
21
+
22
+ Scenario: The address string is fine
23
+ Given an open session
24
+ Then creating a receiver with "my-queue;{create:always}" succeeds
25
+
26
+ Scenario: Using an Address object
27
+ Given an open session
28
+ And an Address with the name "create-receiver-test" and subject "foo" and option "create" set to "always"
29
+ Then creating a receiver with an Address succeeds
@@ -0,0 +1,25 @@
1
+ Feature: Creating a sender
2
+ When working with a session
3
+ As a producer
4
+ I want to create a Sender for sending messages
5
+
6
+ Scenario: The session is closed
7
+ Given a closed session
8
+ Then creating a sender with "my-queue;{create:always}" raises an exception
9
+
10
+ Scenario: The connection is closed
11
+ Given an open session with a closed connection
12
+ Then creating a sender with "my-queue;{create:always}" raises an exception
13
+
14
+ Scenario: The address is malformed
15
+ Given an open session
16
+ Then creating a sender with "my-queue;{foo:bar}" raises an exception
17
+
18
+ Scenario: The address string is valid
19
+ Given an open session
20
+ Then creating a sender with "my-queue;{create:always}" succeeds
21
+
22
+ Scenario: Using an Address object
23
+ Given an open session
24
+ And an Address with the name "my-queue" and subject "my-subject" and option "create" set to "always"
25
+ Then creating a sender with an Address succeeds
@@ -0,0 +1,12 @@
1
+ Feature: Creating a session
2
+ When working with a broker
3
+ As a producer or consumer
4
+ I want to create a session
5
+
6
+ Scenario: The connection is closed
7
+ Given a closed connection
8
+ Then creating a session raises an exception
9
+
10
+ Scenario: The connection is open
11
+ Given an open connection
12
+ Then creating a session works
@@ -0,0 +1,8 @@
1
+ Feature: Getting the authenticated username from an open connection.
2
+ When connected to a broker
3
+ As a producer or consumer
4
+ I can retrieve the username used to authenticate
5
+
6
+ Scenario: When connected anonymously
7
+ Given an open connection
8
+ Then the authenticated username should be "anonymous"
@@ -0,0 +1,28 @@
1
+ Feature: Receving a message
2
+ When working with a broker
3
+ As a message consumer
4
+ I need to be able to receive messages
5
+
6
+ Scenario: Receiving after the session is closed
7
+ Given a sender and receiver for "my-queue;{create:always}"
8
+ And the message "this is a test" is sent
9
+ And the session is closed
10
+ Then getting the next message raises an error
11
+
12
+ Scenario: Receiving after the connection is closed
13
+ Given a sender and receiver for "my-queue;{create:always}"
14
+ And the message "this is a test" is sent
15
+ And the connection is closed
16
+ Then getting the next message raises an error
17
+
18
+ Scenario: No message is received on an empty queue
19
+ Given an existing receiver for "my-queue;{create:always}"
20
+ And the receiver has no pending messages
21
+ Then getting the next message raises an error
22
+
23
+ Scenario: A message is pending
24
+ Given a sender and receiver for "my-queue;{create:always}"
25
+ And the receiver has a capacity of 1
26
+ And the message "this is a test" is sent
27
+ Then the receiver should have 1 message available
28
+ And the receiver should receive a message with "this is a test"
@@ -0,0 +1,21 @@
1
+ Feature: Sending a message
2
+ When working with a broker
3
+ As a producer
4
+ I want to send messages using an existing Sender
5
+
6
+ Scenario: The session is closed
7
+ Given an open session
8
+ And creating a sender with "my-queue;{create:always}" succeeds
9
+ And the session is closed
10
+ Then sending the message "This is a test" should raise an error
11
+
12
+ Scenario: The connection is closed
13
+ Given an open session
14
+ And creating a sender with "my-queue;{create:always}" succeeds
15
+ And the connection is closed
16
+ Then sending the message "This is a test" should raise an error
17
+
18
+ Scenario: The message sends successfully
19
+ Given an open session
20
+ And creating a sender with "my-queue;{create:always}" succeeds
21
+ Then sending the message "This is a test" succeeds
@@ -0,0 +1,12 @@
1
+ Feature: A session returns its connection
2
+ With an action session
3
+ As a producer or consumer
4
+ I can retrieve the underlying connection for the session
5
+
6
+ Scenario: The connection is closed
7
+ Given an open session with a closed connection
8
+ Then the connection for the session is in the closed state
9
+
10
+ Scenario: The connection is open
11
+ Given an open session
12
+ Then the connection for the session is in the open state
@@ -0,0 +1,8 @@
1
+ Feature: Session have a name
2
+ When using a session
3
+ As a producer or consumer
4
+ I can name a session and then later retrieve it by name
5
+
6
+ Scenario: Naming a session
7
+ Given an existing session named "test-session"
8
+ Then the session can be retrieved by the name "test-session"
@@ -0,0 +1,24 @@
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 /^an Address with the name "([^"]*)" and subject "([^"]*)" and option "([^"]*)" set to "([^"]*)"$/ do |name, subject, key, value|
21
+ options = Hash.new
22
+ options["#{key}"] = "#{value}"
23
+ @address = Qpid::Messaging::Address.new "#{name}", "#{subject}", options
24
+ end
@@ -0,0 +1,93 @@
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
+ # close all connections
21
+ After do
22
+ @connection.close if @connection
23
+ end
24
+
25
+ Given /^a new connection$/ do
26
+ @connection = Qpid::Messaging::Connection.new unless @connection
27
+ end
28
+
29
+ Given /^an open connection$/ do
30
+ steps %Q{
31
+ Given a new connection
32
+ }
33
+ @connection.open
34
+ end
35
+
36
+ Given /^a closed connection$/ do
37
+ steps %Q{
38
+ Given a new connection
39
+ }
40
+ @connection.close if @connection.open?
41
+ end
42
+
43
+ Then /^the connection is in the (open|closed) state$/ do |state|
44
+ @connection.open?.should == false if state == "closed"
45
+ @connection.open?.should == true if state == "open"
46
+ end
47
+
48
+ Given /^the connection is opened$/ do
49
+ @connection.open
50
+ end
51
+
52
+ Given /^the connection is closed$/ do
53
+ @connection.close
54
+ end
55
+
56
+ Then /^creating a session raises an exception$/ do
57
+ lambda {
58
+ @session = @connection.create_session
59
+ }.should raise_error
60
+ end
61
+
62
+ Then /^creating a session works$/ do
63
+ steps %Q{
64
+ Given a session exists with the name "nameless"
65
+ }
66
+ @session.should_not be_nil
67
+ end
68
+
69
+ Given /^an existing session named "([^"]*)"$/ do |name|
70
+ steps %Q{
71
+ Given an open connection
72
+ And a session exists with the name "#{name}"
73
+ }
74
+ end
75
+
76
+ Given /^a session exists with the name "([^"]*)"$/ do |name|
77
+ @session = @connection.create_session :name => "#{name}"
78
+ end
79
+
80
+ Then /^the session can be retrieved by the name "([^"]*)"$/ do |name|
81
+ session = @connection.session "#{name}"
82
+ session.should_not be_nil
83
+ end
84
+
85
+ Then /^calling close does not raise an exception$/ do
86
+ lambda {
87
+ @connection.close
88
+ }.should_not raise_error
89
+ end
90
+
91
+ Then /^the authenticated username should be "([^"]*)"$/ do |username|
92
+ @connection.authenticated_username.should == "#{username}"
93
+ end
@@ -0,0 +1,61 @@
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 /^an existing receiver for "([^"]*)"$/ do |address|
21
+ steps %Q{
22
+ Given an open session
23
+ Then creating a receiver with "#{address}" succeeds
24
+ }
25
+ end
26
+
27
+ Given /^the receiver has no pending messages$/ do
28
+ available = @receiver.available
29
+ available.should == 0
30
+ end
31
+
32
+ Then /^getting the next message raises an error$/ do
33
+ lambda {
34
+ @message = @receiver.get Qpid::Messaging::Duration::IMMEDIATE
35
+ }.should raise_error
36
+ end
37
+
38
+ Given /^a sender and receiver for "([^"]*)"$/ do |address|
39
+ steps %Q{
40
+ Given an open session
41
+ Then creating a sender with "#{address}" succeeds
42
+ Then creating a receiver with "#{address}" succeeds
43
+ }
44
+ end
45
+
46
+ Then /^the receiver should receive a message with "([^"]*)"$/ do |content|
47
+ @message = @receiver.fetch Qpid::Messaging::Duration::IMMEDIATE
48
+
49
+ @message.should_not be_nil
50
+ @message.content.should == "#{content}"
51
+ end
52
+
53
+ Given /^the receiver has a capacity of (\d+)$/ do |capacity|
54
+ @receiver.capacity = capacity.to_i
55
+ end
56
+
57
+ Then /^the receiver should have (\d+) message available$/ do |available|
58
+ # TODO we shouldn't need to sleep a second in order to have this update
59
+ sleep 1
60
+ @receiver.available.should == available.to_i
61
+ end