From 21b3b92c21069952f062c804da4e748b8f2db07d Mon Sep 17 00:00:00 2001 From: "Darryl L. Pierce" Date: Thu, 11 Oct 2012 19:43:23 +0000 Subject: JIRA 4291 : Renamed the gemfile to qpid_messaging. Updated the examples and libraries to reflect this change. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1397261 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/bindings/qpid/ruby/Rakefile | 19 +- qpid/cpp/bindings/qpid/ruby/examples/client.rb | 2 +- qpid/cpp/bindings/qpid/ruby/examples/drain.rb | 2 +- .../cpp/bindings/qpid/ruby/examples/hello_world.rb | 2 +- .../bindings/qpid/ruby/examples/map_receiver.rb | 2 +- qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb | 2 +- qpid/cpp/bindings/qpid/ruby/examples/server.rb | 2 +- qpid/cpp/bindings/qpid/ruby/examples/spout.rb | 2 +- .../cpp/bindings/qpid/ruby/features/support/env.rb | 2 +- qpid/cpp/bindings/qpid/ruby/lib/qpid.rb | 29 -- qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb | 187 ----------- qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb | 162 --------- qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb | 95 ------ qpid/cpp/bindings/qpid/ruby/lib/qpid/encoding.rb | 60 ---- qpid/cpp/bindings/qpid/ruby/lib/qpid/errors.rb | 33 -- qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb | 368 --------------------- qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb | 186 ----------- qpid/cpp/bindings/qpid/ruby/lib/qpid/sender.rb | 152 --------- qpid/cpp/bindings/qpid/ruby/lib/qpid/session.rb | 271 --------------- qpid/cpp/bindings/qpid/ruby/lib/qpid/version.rb | 31 -- qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging.rb | 29 ++ .../qpid/ruby/lib/qpid_messaging/address.rb | 187 +++++++++++ .../qpid/ruby/lib/qpid_messaging/connection.rb | 162 +++++++++ .../qpid/ruby/lib/qpid_messaging/duration.rb | 95 ++++++ .../qpid/ruby/lib/qpid_messaging/encoding.rb | 60 ++++ .../qpid/ruby/lib/qpid_messaging/errors.rb | 33 ++ .../qpid/ruby/lib/qpid_messaging/message.rb | 368 +++++++++++++++++++++ .../qpid/ruby/lib/qpid_messaging/receiver.rb | 186 +++++++++++ .../qpid/ruby/lib/qpid_messaging/sender.rb | 152 +++++++++ .../qpid/ruby/lib/qpid_messaging/session.rb | 271 +++++++++++++++ .../qpid/ruby/lib/qpid_messaging/version.rb | 31 ++ qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb | 3 +- 32 files changed, 1592 insertions(+), 1594 deletions(-) delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/encoding.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/errors.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/sender.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/session.rb delete mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid/version.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/address.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/connection.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/duration.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/errors.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/receiver.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/sender.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/session.rb create mode 100644 qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/version.rb diff --git a/qpid/cpp/bindings/qpid/ruby/Rakefile b/qpid/cpp/bindings/qpid/ruby/Rakefile index a813f15b8a..b57855ca4c 100644 --- a/qpid/cpp/bindings/qpid/ruby/Rakefile +++ b/qpid/cpp/bindings/qpid/ruby/Rakefile @@ -29,24 +29,24 @@ require "rubygems/package_task" require "rake/clean" require "rake/extensiontask" -require "rake/rdoctask" +require "rdoc/task" require "rake/testtask" require "cucumber/rake/task" -require "spec/rake/spectask" +require "rspec/core/rake_task" CLOBBER.include("pkg") -load "./lib/qpid/version.rb" +load "./lib/qpid_messaging/version.rb" #------------- # Gem Details. #------------- -NAME = "qpid" +NAME = "qpid_messaging" # VERSION = Qpid::VERSION -AUTHOR = "Darryl L. Pierce" -EMAIL = "dpierce@redhat.com" +AUTHOR = "Apache Qpid Project" +EMAIL = "dev@qpid.apache.org" HOMEPAGE = "http://qpid.apache.org" SUMMARY = "Qpid is an enterprise messaging framework." @@ -63,12 +63,11 @@ task :test => :"test:all" namespace :test do desc "Run RSpec tests." - Spec::Rake::SpecTask.new do |t| + RSpec::Core::RakeTask.new do |t| t.ruby_opts = ['-rtest/unit'] - t.spec_files = FileList["spec/**/*_spec.rb"] - t.rcov = true + t.rcov = false t.rcov_opts = [ - '--exclude', 'lib\/qpid.rb,spec\/,lib\/ruby', + '--exclude', 'lib\/qpid_messaging.rb,spec\/,lib\/ruby', ] end diff --git a/qpid/cpp/bindings/qpid/ruby/examples/client.rb b/qpid/cpp/bindings/qpid/ruby/examples/client.rb index 86ec1b7254..be7e70722e 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/client.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/client.rb @@ -19,7 +19,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") -require 'qpid' +require 'qpid_messaging' if __FILE__ == $0 broker = ARGV[1] || "amqp:tcp:localhost:5672" diff --git a/qpid/cpp/bindings/qpid/ruby/examples/drain.rb b/qpid/cpp/bindings/qpid/ruby/examples/drain.rb index 9e8f699e8b..8e506ea5cd 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/drain.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/drain.rb @@ -19,7 +19,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") -require 'qpid' +require 'qpid_messaging' require 'optparse' options = { diff --git a/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb b/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb index c014fb8bd5..1f4954dde9 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb @@ -19,7 +19,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") -require 'qpid' +require 'qpid_messaging' # This is your classic Hello World application, written in # Ruby, that uses Qpid. It demonstrates how to send and diff --git a/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb b/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb index e08bd295ba..16704dd48e 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb @@ -19,7 +19,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") -require 'qpid' +require 'qpid_messaging' broker = ARGV[0] || "amqp:tcp:127.0.0.1:5672" address = ARGV[1] || "message_queue; {create: always}" diff --git a/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb b/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb index 3fb7ca58e3..1908774c31 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb @@ -19,7 +19,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") -require 'qpid' +require 'qpid_messaging' broker = ARGV[0] || "amqp:tcp:127.0.0.1:5672" address = ARGV[1] || "message_queue; {create: always}" diff --git a/qpid/cpp/bindings/qpid/ruby/examples/server.rb b/qpid/cpp/bindings/qpid/ruby/examples/server.rb index 0cc0e30216..a589bea799 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/server.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/server.rb @@ -19,7 +19,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") -require 'qpid' +require 'qpid_messaging' if __FILE__ == $0 broker = ARGV[0] || "amqp:tcp:localhost:5672" diff --git a/qpid/cpp/bindings/qpid/ruby/examples/spout.rb b/qpid/cpp/bindings/qpid/ruby/examples/spout.rb index ecc47fb15a..71c04d8709 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/spout.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/spout.rb @@ -19,7 +19,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib") -require 'qpid' +require 'qpid_messaging' require 'optparse' options = { diff --git a/qpid/cpp/bindings/qpid/ruby/features/support/env.rb b/qpid/cpp/bindings/qpid/ruby/features/support/env.rb index 1d15f56fc9..cc0097ca8b 100644 --- a/qpid/cpp/bindings/qpid/ruby/features/support/env.rb +++ b/qpid/cpp/bindings/qpid/ruby/features/support/env.rb @@ -19,4 +19,4 @@ $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../../lib") -require 'qpid' +require 'qpid_messaging' diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid.rb deleted file mode 100644 index 1f00c136c1..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'qpid/errors' -require 'qpid/duration' -require 'qpid/address' -require 'qpid/encoding' -require 'qpid/message' -require 'qpid/sender' -require 'qpid/receiver' -require 'qpid/session' -require 'qpid/connection' - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb deleted file mode 100644 index 266d8668d6..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/address.rb +++ /dev/null @@ -1,187 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'cqpid' - -module Qpid - - module Messaging - - # Address represents an address to which messages can be sent or from - # which they can be received. - # - # An Address can be described using the following pattern: - # - #
[ / ] ; [ { : , ... } ] - # - # where *address* is a simple name and *subject* is a subject or subject - # pattern. - # - # The options, enclosed in curly braces, are key:value pairs delimited by - # a comma. The values can be nested maps also enclosed in curly braces. - # Or they can be lists of values, where they are contained within square - # brackets but still comma delimited, such as: - # - # [value1,value2,value3] - # - # The following are the list of supported options: - # - # [:create] - # Indicates if the address should be created; values are *always*, - # *never*, *sender* or *reciever*. - # - # [:assert] - # Indicates whether or not to assert any specified node properties; - # values are *always*, *never*, *sender* or *receiver*. - # - # [:delete] - # Indicates whether or not to delete the addressed node when a sender - # or receiver is cancelled; values are *always*, *never*, *sender* or - # *receiver*. - # - # [:node] - # A nested map describing properties for the addressed node. Properties - # are *type* (*topic* or *queue*), *durable* (a boolean), *x-declare* - # (a nested map of amqp 0.10-specific options) and *x-bindings*. (nested - # list which specifies a queue, exchange or a binding key and arguments. - # - # [:link] - # A nested map through which properties of the link can be specified; - # properties are *durable*, *reliability*, *x-declare*, *x-subscribe* - # and *x-bindings*. - # - # [:mode] - # (*For receivers only*) indicates whether the receiver should consume - # or browse messages; values are *consume* (the default) and *browse*. - # - class Address - - # Creates a new +Address+ object. - # - # ==== Options - # - # * name - The name for the +Address+. - # * subject - The subject for the +Address+ - # * :create - See the class documentation. - # * :assert - See the class documentation. - # * :delete - See the class documentation. - # * :node - See the class documentation. - # * :link - See the class documentation. - # * :mode - See the class documentation. - # - # ==== Examples - # - # addr = Qpid::Messaging::Address.new "my-queue" - # addr = Qpid::Messaging::Address.new "my-queue", "testing", :create => :always - # - def initialize(name, subject, options = {}, _type = "", address_impl = nil) - @address_impl = address_impl || Cqpid::Address.new(name, subject, convert_options(options), _type) - end - - def address_impl # :nodoc: - @address_impl - end - - # Returns the name for the +Address+. - # - # ==== Examples - # - # puts "The address name is #{addr.name}." - # - def name; @address_impl.getName; end - - # Sets the name for the +Address+. - # - # ==== Examples - # - # addr.name = "my-new-queue" - # - def name=(name); @address_impl.setName name; end - - # Returns the subject for the +Address+. - # - # ==== Examples - # - # puts "The subject is #{addr.subject}." - # - def subject; @address_impl.getSubject; end - - # Sets the subject for the +Address+. - # - # ==== Examples - # - # addr.subject = "testing" - # - def subject=(subject); @address_impl.setSubject(subject); end - - # Returns the type for the +Address+. - # - # ==== Examples - # - # puts "The address is a #{address.address_type}." - # - #--- - # We cannot use "type" since that clashes with the Ruby object.type - # identifier. - def address_type; @address_impl.getType; end - - # Sets the type for the +Address+. - # - # The type of the address determines how +Sender+ and +Receiver+ objects - # are constructed for it. If no type is specified then it will be - # determined by querying the broker. - # - # ===== Options - # - # * type - the address type - # - def address_type=(type); @address_impl.setType(type); end - - # Returns the options. - def options; @address_impl.getOptions; end - - # Sets the options for the address. - # - # *NOTE:* See the class documentation for more details on options. - # - # ==== Examples - # - # addr.options = :create => :always - # - def options=(options = {}); @address_impl.setOptions(convert_options(options)); end - - def to_s # :nodoc: - @address_impl.str - end - - private - - def convert_options(options) - result = {} - options.each_pair {|key, value| result[key.to_s] = value.to_s} - - return result - end - - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb deleted file mode 100644 index 12669bc947..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/connection.rb +++ /dev/null @@ -1,162 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'cqpid' - -module Qpid - - module Messaging - - # Establishes a connection to a remote endpoint. - class Connection - - attr_reader :options # :nodoc: - - # Creates a connection object, but does not actually connect to - # the specified location. - # - # ==== Options - # - # :url - the URL for the broker (def. +"localhost"+) - # :options - connection options (def. +{}+) - # - # ==== Controlling Reconnect Behavior - # - # The following connection options can be used to configure - # the reconnection behavior for this connection. - # - # * :username - # * :password - # * :heartbeat - # * :tcp_nodelay - # * :sasl_mechanism - # * :sasl_service - # * :sasl_min_ssf - # * :sasl_max_ssf - # * :transport - # * :reconnect - +true+ or +false+; indicates wehtehr to attempt reconnections - # * :reconnect_timeout - the number of seconds to attempt reconnecting - # * :reconnect_limit - the number of retries before reporting failure - # * :reconnect_interval_min - initial delay, in seconds, before attempting a reconnection - # * :reconnect_interval_max - number of seconds to wait before additional reconnect attempts - # * :reconnect_interval - shorthand for setting both min and max values - # * :reconnect_urls - a list of alternate URLs to use for reconnection attempts - # - # ==== Examples - # - # conn = Qpid::Messaging::Connnection.new - # conn = Qpid::Messaging::Connection.new :url => "amqp:tcp:broker1.domain.com:5672" - # conn = Qpid::Messaging::Connection.new :options => {:username => "login", :password => "password"} - # - def initialize(opts = {}) - @url = opts[:url] || "localhost" - @options = convert_options(opts[:options] || {}) - @connection_impl = opts[:impl] || Cqpid::Connection.new(@url, @options) - end - - def connection_impl # :nodoc: - @connection_impl - end - - # Establishes the connection. - # - # ==== Examples - # - # conn.open unless conn.open? - # - def open - @connection_impl.open - end - - # Reports whether the connection is open. - # - # ==== Examples - # - # conn.close if conn.open? - # - def open?; true && !@connection_impl.nil? && @connection_impl.isOpen; end - - # Closes the connection. - def close; @connection_impl.close; end - - # Creates a new session. - # - # ==== Arguments - # - # * :name - specifies the name for this session - # * :transactional - if +true+ then a creates a transaction session (def. +false+) - # - # ==== Examples - # - # session = conn.create_session :name => "session1" - # session = conn.create_session :transaction => true - # - def create_session(args = {}) - name = args[:name] || "" - if open? - if args[:transactional] - session = @connection_impl.createTransactionalSession name - else - session = @connection_impl.createSession name - end - return Session.new(self, session) - else - raise RuntimeError.new "No connection available." - end - end - - # Returns a session for the specified session name. - # - # ==== Examples - # - # begin - # session = conn.session "mysession" - # rescue SessionNameException => error - # puts "No such session." - # end - # - def session name - begin - session_impl = @connection_impl.getSession name - Qpid::Messaging::Session.new self, session_impl if session_impl - rescue - raise Qpid::Messaging::SessionNameException.new "No such session: #{name}" - end - end - - # Returns the username used to authenticate with the connection. - def authenticated_username; @connection_impl.getAuthenticatedUsername if open?; end - - private - - def convert_options(options) - result = {} - unless options.nil? || options.empty? - options.each_pair {|key, value| result[key.to_s] = value.to_s} - end - - return result - end - - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb deleted file mode 100644 index e1ddd79cb6..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/duration.rb +++ /dev/null @@ -1,95 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'cqpid' - -module Qpid - - module Messaging - - # A Duration represents a period of time in milliseconds - # - # It defines the following named values as symbols: - # - # [:FOREVER] - # The maximum integer value for the platform. Effectively this will wait - # forever. - # - # [:IMMEDIATE] - # An alias for 0 milliseconds. - # - # [:SECOND] - # An alias for 1,000 milliseconds. - # - # [:MINUTE] - # And alias for 60,000 millisecons. - # - class Duration - - # Creates a Duration with the specified length, in milliseconds. - # - # ==== Options - # - # * length - The duration in milliseconds. - # - # ==== Examples - # - # # Wait up to 10 seconds for an incoming message - # receiver.get Qpid::Messaging::Duration.new 10000 - # - def initialize length - @duration_impl = Cqpid::Duration.new length - end - - def duration_impl # :nodoc: - @duration_impl - end - - # Returns the period of time in milliseconds - # - # ==== Examples - # - # duration = Qpid::Messaging::Duration.new :length => 5000 - # puts "Waiting #{duration.milliseconds} ms for a message." - # msg = receiver.fetch duration - # - def milliseconds - @duration_impl.getMilliseconds - end - - def self.add_item(key, value) # :nodoc: - @hash ||= {} - @hash[key] = Duration.new value - end - - def self.const_missing(key) # :nodoc: - @hash[key] - end - - self.add_item :FOREVER, Cqpid::Duration.FOREVER.getMilliseconds - self.add_item :IMMEDIATE, Cqpid::Duration.IMMEDIATE.getMilliseconds - self.add_item :SECOND, Cqpid::Duration.SECOND.getMilliseconds - self.add_item :MINUTE, Cqpid::Duration.MINUTE.getMilliseconds - - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/encoding.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/encoding.rb deleted file mode 100644 index 2f20fab18e..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/encoding.rb +++ /dev/null @@ -1,60 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'cqpid' - -module Qpid - - module Messaging - - # Encodes the supplied content into the given message. - def self.encode content, message, encoding = nil - prepared = content - case content - when Hash - prepared = {} - content.each_pair do |key,value| - prepared[key.to_s] = value.to_s - end - Cqpid::encode prepared, message.message_impl - when Array - prepared = [] - content.each {|value| prepared << value.to_s} - Cqpid::encode prepared, message.message_impl - end - end - - # Decodes and returns the message's content. - def self.decode(message, content_type = nil) - content_type = message.content_type unless content_type - - case content_type - when "amqp/map" - Cqpid.decodeMap message.message_impl - when "amqp/list" - Cqpid.decodeList message.message_impl - end - - message.content - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/errors.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/errors.rb deleted file mode 100644 index c98eb1ac12..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/errors.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -module Qpid - - module Messaging - - class KeyError < RuntimeError; end - - class SessionNameException < Exception - def initialize(msg); super(msg); end - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb deleted file mode 100644 index edef0ac2a0..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/message.rb +++ /dev/null @@ -1,368 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'cqpid' - -module Qpid - - module Messaging - - # A +Message+ represents an routable piece of information. - # - # The content for a message is automatically encoded and decoded. - # - class Message - - # Creates a new instance of +Message+. - # - # ==== Options - # - # * :content - The content. - # - # ==== Examples - # - # message = Qpid::Messaging::Message.new :content => "This is a message." - # - def initialize(args = {}) - @message_impl = (args[:impl] if args[:impl]) || nil - @message_impl = Cqpid::Message.new if @message_impl.nil? - @content = nil - args = {} if args.nil? - self.content = args[:content] if args[:content] - end - - def message_impl # :nodoc: - @message_impl - end - - # Sets the address to which replies should be sent for the +Message+. - # - # *NOTE:* The address must be an instance of Address. - # - # ==== Options - # - # * address - an instance of +Address+ - # - # ==== Examples - # - # msg.reply_to = Qpid:Messaging::Address.new "my-responses" - # - def reply_to=(address) - raise ArgumentError, "Agument must be an Address" unless address.is_a? Qpid::Messaging::Address - @message_impl.setReplyTo address.address_impl - end - - # Returns the reply to address for the +Message+. - # - def reply_to - address_impl = @message_impl.getReplyTo - # only return an address if a reply to was specified - Qpid::Messaging::Address.new(nil, nil, nil, nil, address_impl) if address_impl - end - - # Sets the subject for the +Message+. - # - # ==== Options - # - # * subject - the subject - # - # ==== Examples - # - # msg.subject = "mysubject" - # - def subject=(subject); @message_impl.setSubject subject; end - - # Returns the subject of the +Message+. - # - # ==== Options - # - # puts "The subject is #{msg.subject}" - # - def subject; @message_impl.getSubject; end - - # Sets the content type for the +Message+. - # - # This should be set by the sending applicaton and indicates to - # recipients of the message how to interpret or decode the content. - # - # By default, only dictionaries and maps are automatically given a content - # type. If this content type is replaced then retrieving the content will - # not behave correctly. - # - # ==== Options - # - # * content_type - the content type. - # - def content_type=(content_type); @message_impl.setContentType content_type; end - - # Returns the content type for the +Message+. - # - # ==== Examples - # - # case msg.content_type - # when "myapp/image" - # ctl.handle_image msg - # end - # when "myapp/audio" - # ctl.handle_audio msg - # end - # end - # - def content_type; @message_impl.getContentType; end - - # Sets the message id. - # - # *NOTE:* this field must be a UUID type currently. A non-UUID value will - # be converted to a zero UUID, though a blank ID will be left untouched. - # - # ==== Options - # - # * id - the id - # - # ==== Examples - # - # - def message_id=(message_id); @message_impl.setMessageId message_id.to_s; end - - # Returns the message id. - # - # See +message_id=+ for details. - def message_id; @message_impl.getMessageId; end - - # Sets the user id for the +Message+. - # - # This should in general be the user-id which was used when authenticating - # the connection itself, as the messaging infrastructure will verify - # this. - # - # See +Qpid::Messaging::Connection.authenticated_username+ - # - # *NOTE:* If the id is not a +String+ then the id is set using - # the object's string representation. - # - # ==== Options - # - # * id - the id - # - def user_id=(user_id); @message_impl.setUserId user_id; end - - # Returns the user id for the +Message+. - # - # See +user_id=+ for details. - # - def user_id; @message_impl.getUserId; end - - # Sets the correlation id of the +Message+. - # - # The correlation id can be used as part of a protocol for message - # exchange patterns; e.g., a requestion-response pattern might require - # the correlation id of the request and the response to match, or it - # might use the message id of the request as the correlation id on - # the response - # - # *NOTE:* If the id is not a +String+ then the id is setup using - # the object's string representation. - # - # ==== Options - # - # * id - the id - # - def correlation_id=(correlation_id); @message_impl.setCorrelationId correlation_id; end - - # Returns the correlation id of the +Message+. - # - # *NOTE:* See +correlation_id=+ for details. - # - def correlation_id; @message_impl.getCorrelationId; end - - # Sets the priority of the +Message+. - # - # This may be used by the messaging infrastructure to prioritize - # delivery of messages with higher priority. - # - # *NOTE:* If the priority is not an integer type then it is set using - # the object's integer representation. If the integer value is greater - # than 8-bits then only the first 8-bits are used. - # - # ==== Options - # - # * priority - the priority - # - def priority=(priority); @message_impl.setPriority priority; end - - # Returns the priority for the +Message+. - # - def priority; @message_impl.getPriority; end - - # Sets the time-to-live in milliseconds. - # - # ==== Options - # - # * duration - the number of milliseconds - # - def ttl=(duration) - if duration.is_a? Qpid::Messaging::Duration - @message_impl.setTtl duration.duration_impl - else - @message_impl.setTtl Cqpid::Duration.new duration.to_i - end - end - - # Returns the time-to-live in milliseconds. - def ttl; Qpid::Messaging::Duration.new @message_impl.getTtl.getMilliseconds; end - - # Sets the durability of the +Message+. - # - # This is a hint to the messaging infrastructure that the message - # should be persisted or otherwise stored. This helps to ensure - # that th emessage is not lost during to failures or a shutdown. - # - # ==== Options - # - # * durable - the durability flag (def. false) - # - def durable=(durable); @message_impl.setDurable durable; end - - # Returns the durability for the +Message+. - # - def durable; @message_impl.getDurable; end - - # This is a hint to the messaging infrastructure that if de-duplication - # is required, that this message should be examined to determine if it - # is a duplicate. - # - # ==== Options - # - # * redelivered - sets the redelivered state (def. false) - # - # ==== Examples - # - # # processed is an array of processed message ids - # msg.redelivered = true if processed.include? msg.message_id - # - def redelivered=(redelivered); @message_impl.setRedelivered redelivered; end - - # Returns whether the +Message+ has been marked as redelivered. - # - def redelivered; @message_impl.getRedelivered; end - - # Returns all named properties. - # - # *NOTE:* It is recommended to use the []= method for - # retrieving and setting properties. Using this method may - # result in non-deterministic behavior. - # - def properties; @message_impl.getProperties; end - - # Returns the value for the named property. - # - # ==== Options - # - # * name - the property name - # - # ==== Examples - # - # # use of message properties to mark a message as digitally signed - # verify(msg) if msg[:signed] - # - def [](key); self.properties[key.to_s]; end - - # Assigns a value to the named property. - # - # *NOTE:* Both the key or the value may be a symbol, but they will - # both be converted to a +String+ for ease of transport. - # - # ==== Options - # - # * name - the property name - # * value - the property value - def []=(key, value); @message_impl.setProperty(key.to_s, value.to_s); end - - # Sets the content for the +Message+. - # - # Content is automatically encoded for Array and Hash types. Other types - # need to set their own content types (via +content_type+) in order to - # specify how recipients should process the content. - # - # ==== Options - # - # * content - the content - # - # ==== Examples - # - # msg.content = "This is a simple message." # a simple message - # msg.content = {:foo => :bar} # content is automatically encoded - # - def content=(content) - content_type = nil - @content = content - case @content - when Hash - content_type = "amqp/map" - new_content = {} - content.each_pair{|key, value| new_content[key.to_s] = value.to_s} - @content = new_content - when Array - new_content = [] - content_type = "amqp/list" - content.each {|element| new_content << element.to_s} - @content = new_content - end - if content_type.nil? - @message_impl.setContent @content - else - Qpid::Messaging.encode @content, self, content_type - end - end - - # Returns the content of the +Message+. - # - # Content is automatically decoded based on the specified content type. - # If the content type is application-specific, then no decoding is - # performed and the content is returnedas a +String+ representation. - # - # For example, if an array of integers are sent, then the receiver will - # find the message content to be an array of String objects, where each - # String is a representation of the sent integer value. - # - def content - if @content.nil? - @content = @message_impl.getContent - - # decode the content is necessary if it - # has an encoded content type - if ["amqp/list", "amqp/map"].include? @message_impl.getContentType - @content = Qpid::Messaging.decode(self, - @message_impl.getContentType) - end - - end - @content - end - - # Returns the content's size. - # - def content_size; @message_impl.getContentSize; end - - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb deleted file mode 100644 index 0ce16309ed..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/receiver.rb +++ /dev/null @@ -1,186 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'cqpid' - -require 'qpid/duration' - -module Qpid - - module Messaging - - # Receiver is the entity through which messages are received. - # - # An instance of Receiver can only be created using an active (not - # previously closed) Session. - # - # ==== Example - # - # conn = Qpid::Messaging::Connection.new :url => "mybroker:5762" - # conn.open - # session = conn.create_session - # receiver = session.create_receiver "my-sender-queue" - class Receiver - - def initialize(session, receiver_impl) # :nodoc: - @session = session - @receiver_impl = receiver_impl - end - - def receiver_impl # :nodoc: - @receiver_impl - end - - # Retrieves a message from the local queue, or waits for up to - # the duration specified for one to become available. - # - # If a block is given, then it will be invaked after the next message - # is received or the call times out, passing in the message or nil - # respectively. - # - # ==== Options - # * duration - the timeout to wait (def. Duration::FOREVER) - # - # ==== Examples - # - # msg = rcvr.get # Uses the default timeout of forever - # - # msg = rcvr.get Qpid::Messaging::Duration::IMMEDIATE # returns a message or exits immediately - # - # # passes in a block to handle the received message - # rcvr.get Qpid::Messaging::Duration::SECOND do |message| - # if message.nil? - # puts "No message was received." - # else - # puts "Received this message: #{message.content}" - # end - # end - def get(duration = Qpid::Messaging::Duration::FOREVER) - message_impl = @receiver_impl.get duration.duration_impl - create_message_wrapper message_impl unless message_impl.nil? - end - - # Retrieves a message from the receiver's subscription, or waits - # for up to the duration specified for one to become available. - # - # If a block is given, then it will be invaked after the next message - # is received or the call times out, passing in the message or nil - # respectively. - # - # ==== Options - # * duration - the timeout to wait (def. Duration::FOREVER) - # - # ==== Examples - # - # msg = rcvr.fetch # Uses the default timeout of forever - # - # msg = rcvr.fetch Qpid::Messaging::Duration::IMMEDIATE # returns a message or exits immediately - # - # # passes in a block to handle the received message - # rcvr.fetch Qpid::Messaging::Duration::SECOND do |message| - # if message.nil? - # puts "No message was received." - # else - # puts "Received this message: #{message.content}" - # end - # end - def fetch(duration = Qpid::Messaging::Duration::FOREVER) - message_impl = @receiver_impl.fetch duration.duration_impl - create_message_wrapper message_impl unless message_impl.nil? - end - - # Sets the capacity for this +Receiver+. - # - # ==== Options - # - # * capacity - the capacity - # - # ==== Examples - # - # receiver.capacity = 50 # sets the incoming capacity to 50 messages - # - def capacity=(capacity); @receiver_impl.setCapacity capacity; end - - # Returns the capacity. - # - # - # The capacity is the numnber of incoming messages that can be held - # locally before being fetched. - # - # ==== Examples - # - # puts "The receiver can hold #{rcv.capacity} messages." - # - def capacity; @receiver_impl.getCapacity; end - - # Returns the number of slots for receiving messages. - # - # This differs from +capacity+ in that it is the available slots in - # the capacity for holding incoming messages, where available <= capacity. - # - # ==== Examples - # - # puts "You can receive #{rcv.available} messages before blocking." - # - def available; @receiver_impl.getAvailable; end - - # Returns the number of messages that have been received and acknowledged - # but whose acknowledgements have not been confirmed by the sender. - # - # ==== Examples - # - # puts "You have #{rcv.unsettled} messages to be confirmed." - # - def unsettled; @receiver_impl.getUnsettled; end - - # Closes this +Receiver+. - # - # This does not affect the +Session+. - def close; @receiver_impl.close; end - - # Returns whether the receiver is closed. - # - # ==== Examples - # - # recv.close unless recv.closed? - # - def closed?; @receiver_impl.isClosed; end - - # Returns the name of this +Receiver+. - # - # ==== Examples - # - # puts "Receiver: #{recv.name}" - def name; @receiver_impl.getName; end - - # Returns the Session for this +Receiver+. - def session; @session; end - - private - - def create_message_wrapper message_impl # :nodoc: - Qpid::Messaging::Message.new(:impl => message_impl) - end - - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/sender.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/sender.rb deleted file mode 100644 index 97227622f5..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/sender.rb +++ /dev/null @@ -1,152 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -module Qpid - - module Messaging - - # Sender is the entity through which messages sent. - # - # An instance of Sender can only be created using an active (not previously - # closed) Session. - # - # ==== Examples - # - # conn = Qpid::Messaging::Connection.new :url => "mybroker:5762" - # conn.open - # session = conn.create_session - # sender = session.create_session "my-sender-queue;{create:always}" - class Sender - - def initialize(session, sender_impl) # :nodoc: - @session = session - @sender_impl = sender_impl - end - - def sender_impl # :nodoc: - @sender_impl - end - - # Sends a message. - # - # If a block is given, then it will be invoked after the message - # is sent. - # - # ==== Options - # - # * message - The message to send. - # * :sync - See note below on synching. - # - # ==== Synching - # - # If :sync => true, then the call will block until the broker confirms - # receipt of the message. Otherwise it will only block for available - # capacity; i.e., until pending is equal to capacity. - # - # ==== Examples - # - # sender.send message do |message| - # puts "Message sent: #{message.content}" - # end - # - def send(message, args = {}, &block) - sync = args[:sync] || false - @sender_impl.send message.message_impl, sync - block.call message unless block.nil? - end - - # Closes this +Sender+. - # - # This does not affect the +Session+. - def close; @sender_impl.close; end - - # Returns the human-readable name for this +Sender+. - # - # ==== Examples - # - # puts "Sender: #{sender.name}" - # - def name; @sender_impl.getName; end - - # Sets the capacity for this +Sender+. - # - # The capacity is the number of outgoing messages that can be held - # pending confirmation or receipt by the broker. - # - # ==== Options - # - # * capacity - the capacity - # - # ==== Examples - # - # sender.capacity = 50 # sets the outgoing capacity to 50 messages - # - def capacity=(capacity); @sender_impl.setCapacity capacity; end - - # Returns the capacity. - # - # The capacity is the total number of outgoing messages that can be - # sent before a called to +send+ begins to block by default. - # - # ==== Examples - # - # puts "You can send a maximum of #{sender.capacity} messages." - # - def capacity; @sender_impl.getCapacity; end - - # Returns the number of messages sent that are pending receipt - # confirmation by the broker. - # - # ==== Examples - # - # if sender.unsettled > 0 - # puts "There are #{sender.unsettled} messages pending." - # end - # - def unsettled; @sender_impl.getUnsettled; end - - # Returns the available slots for sending messages. - # - # This differs from +capacity+ in that it is the available slots in - # the senders capacity for holding outgoing messages. The difference - # between capacity and available is the number of messages that - # have not been delivered yet. - # - # ==== Examples - # - # puts "You can send #{sender.available} messages before blocking." - # - def available - @sender_impl.getAvailable - end - - # Returns the +Session+ for this sender. - # - # ==== Examples - # - # recv.session.close if done - # - def session; @session; end - - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/session.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/session.rb deleted file mode 100644 index feb8aa5bb4..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/session.rb +++ /dev/null @@ -1,271 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -require 'cqpid' - -require 'qpid/errors' - -module Qpid - - module Messaging - - # A Session represents a distinct conversation between end points. - class Session - - def initialize(connection, session) # :nodoc: - @connection = connection - @session_impl = session - @senders = Hash.new - @receivers = Hash.new - end - - def session_impl # :nodoc: - @session_impl - end - - # Returns the +Connection+ associated with this session. - def connection - @connection - end - - # Creates a new endpoint for sending messages. - # - # The +address+ can either be an instance +Address+ or else a - # string that describes an address endpoint. - # - # ==== Arguments - # - # * +address+ The end point address. - # - # ==== Examples - # - # sender = session.create_sender "my-queue;{create:always}" - # - def create_sender(address) - _address = address - - if address.class == Qpid::Messaging::Address - _address = address.address_impl - end - - sender_impl = @session_impl.createSender(_address) - sender_name = sender_impl.getName - - @senders[sender_name] = Qpid::Messaging::Sender.new(self, sender_impl) - - @senders[sender_name] - end - - # Retrieves the +Sender+ with the specified name. - # - # The +Sender+ must have been previously created using - # the +create_sender+ method. - # - # ==== Arguments - # - # * +name+ The +Sender+ name. - # - # ==== Examples - # - # sender = session.sender "my-queue" - # - def sender(name) - raise Qpid::Messaging::KeyError, "No such sender: #{name}" unless @senders.has_key? name - - @senders[name] - end - - # Creates a new endpoint for receiving messages. - # - # The +address+ can either be an instance +Address+ or else a - # string that describes an address endpoint. - # - # ==== Arguments - # - # * +address+ The end point address. - # - # ==== Examples - # - # receiver = session.create_receiver "my-queue" - # - def create_receiver(address) - result = nil - receiver_impl = nil - - if address.class == Qpid::Messaging::Address - address_impl = address.address_impl - receiver_impl = @session_impl.createReceiver address_impl - else - receiver_impl = @session_impl.createReceiver(address) - end - - receiver_name = receiver_impl.getName - - @receivers[receiver_name] = Qpid::Messaging::Receiver.new self, receiver_impl - - @receivers[receiver_name] - end - - # Retrieves the +Receiver+ with the specified name. - # - # The +Receiver+ must have been previously created using - # the +create_receiver+ method. - # - # ==== Arguments - # - # * +name+ The +Receiver+ name. - # - # ==== Examples - # - # receiver = session.receiver "my-queue" - # - def receiver(name) - raise Qpid::Messaging::KeyError, "No such receiver: #{name}" unless @receivers.has_key? name - - @receivers[name] - end - - # Closes the +Session+ and all associated +Sender+ and +Receiver+ instances. - # - # NOTE: All +Session+ instances for a +Connection+ are closed when the - # +Connection+ is closed. - def close; @session_impl.close; end - - # Commits any pending transactions for a transactional session. - def commit; @session_impl.commit; end - - # Rolls back any uncommitted transactions on a transactional session. - def rollback; @session_impl.rollback; end - - # Acknowledges one or more outstanding messages that have been received - # on this session. - # - # ==== Arguments - # - # * :message - if specified, then only the +Message+ specified is acknowledged - # * :sync - if true then the call will block until processed by the server (def. false) - # - # ==== Examples - # - # session.acknowledge # acknowledges all received messages - # session.acknowledge :message => message # acknowledge one message - # session.acknowledge :sync => true # blocks until the call completes - # - #-- - # TODO: Add an optional block to be used for blocking calls. - #++ - def acknowledge(args = {}) - sync = args[:sync] || false - message = args[:message] if args[:message] - - unless message.nil? - @session_impl.acknowledge message.message_impl, sync - else - @session_impl.acknowledge sync - end - end - - # Rejects the specified message. A rejected message will not be - # redelivered. - # - # NOTE: A message cannot be rejected once it has been acknowledged. - def reject(message); @session_impl.reject message.message_impl; end - - # Releases the message, which allows the broker to attempt to - # redeliver it. - # - # NOTE: A message connot be released once it has been acknowled. - def release(message); @session_impl.release message.message_impl; end - - # Requests synchronization with the server. - # - # ==== Arguments - # - # * :block - if true then the call blocks until the server acknowledges it (def. false) - # - #-- - # TODO: Add an optional block to be used for blocking calls. - #++ - def sync(args = {}) - block = args[:block] || false - @session_impl.sync block - end - - # Returns the total number of receivable messages, and messages already - # received, by +Receiver+ instances associated with this +Session+. - def receivable; @session_impl.getReceivable; end - - # Returns the number of messages that have been acknowledged by this session - # whose acknowledgements have not been confirmed as processed by the server. - def unsettled_acks; @session_impl.getUnsettledAcks; end - - # Fetches the +Receiver+ for the next message. - # - # ==== Arguments - # - # * timeout - time to wait for a +Receiver+ before timing out - # - # ==== Examples - # - # recv = session.next_receiver # wait forever for the next +Receiver+ - # # execute a block on the next receiver - # session.next_receiver do |recv| - # msg = recv.get - # puts "Received message: #{msg.content}" - # end - def next_receiver(timeout = Qpid::Messaging::Duration::FOREVER, &block) - receiver_impl = @session_impl.nextReceiver(timeout.duration_impl) - - unless receiver_impl.nil? - recv = Qpid::Messaging::Receiver.new self, receiver_impl - block.call recv unless block.nil? - end - - return recv - end - - # Returns true if there were exceptions on this session. - # - # ==== Examples - # - # puts "There were session errors." if @session.errors? - def errors?; @session_impl.hasError; end - - # If the +Session+ has been rendered invalid due to some exception, - # this method will result in that exception being raised. - # - # If none have occurred, then no exceptions are raised. - # - # ==== Examples - # - # if @session.errors? - # begin - # @session.errors - # rescue Exception => error - # puts "An error occurred: #{error}" - # end - # end - def errors; @session_impl.checkError; end - - end - - end - -end - diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid/version.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid/version.rb deleted file mode 100644 index 737f021006..0000000000 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid/version.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -module Qpid #:nodoc: - - module Version - - NUMBERS = [MAJOR = 0, - MINOR = 17, - BUILD = 0] - end - - VERSION = Version::NUMBERS.join('.') - -end diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging.rb new file mode 100644 index 0000000000..38943447fe --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging.rb @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'qpid_messaging/errors' +require 'qpid_messaging/duration' +require 'qpid_messaging/address' +require 'qpid_messaging/encoding' +require 'qpid_messaging/message' +require 'qpid_messaging/sender' +require 'qpid_messaging/receiver' +require 'qpid_messaging/session' +require 'qpid_messaging/connection' + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/address.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/address.rb new file mode 100644 index 0000000000..266d8668d6 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/address.rb @@ -0,0 +1,187 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'cqpid' + +module Qpid + + module Messaging + + # Address represents an address to which messages can be sent or from + # which they can be received. + # + # An Address can be described using the following pattern: + # + #
[ / ] ; [ { : , ... } ] + # + # where *address* is a simple name and *subject* is a subject or subject + # pattern. + # + # The options, enclosed in curly braces, are key:value pairs delimited by + # a comma. The values can be nested maps also enclosed in curly braces. + # Or they can be lists of values, where they are contained within square + # brackets but still comma delimited, such as: + # + # [value1,value2,value3] + # + # The following are the list of supported options: + # + # [:create] + # Indicates if the address should be created; values are *always*, + # *never*, *sender* or *reciever*. + # + # [:assert] + # Indicates whether or not to assert any specified node properties; + # values are *always*, *never*, *sender* or *receiver*. + # + # [:delete] + # Indicates whether or not to delete the addressed node when a sender + # or receiver is cancelled; values are *always*, *never*, *sender* or + # *receiver*. + # + # [:node] + # A nested map describing properties for the addressed node. Properties + # are *type* (*topic* or *queue*), *durable* (a boolean), *x-declare* + # (a nested map of amqp 0.10-specific options) and *x-bindings*. (nested + # list which specifies a queue, exchange or a binding key and arguments. + # + # [:link] + # A nested map through which properties of the link can be specified; + # properties are *durable*, *reliability*, *x-declare*, *x-subscribe* + # and *x-bindings*. + # + # [:mode] + # (*For receivers only*) indicates whether the receiver should consume + # or browse messages; values are *consume* (the default) and *browse*. + # + class Address + + # Creates a new +Address+ object. + # + # ==== Options + # + # * name - The name for the +Address+. + # * subject - The subject for the +Address+ + # * :create - See the class documentation. + # * :assert - See the class documentation. + # * :delete - See the class documentation. + # * :node - See the class documentation. + # * :link - See the class documentation. + # * :mode - See the class documentation. + # + # ==== Examples + # + # addr = Qpid::Messaging::Address.new "my-queue" + # addr = Qpid::Messaging::Address.new "my-queue", "testing", :create => :always + # + def initialize(name, subject, options = {}, _type = "", address_impl = nil) + @address_impl = address_impl || Cqpid::Address.new(name, subject, convert_options(options), _type) + end + + def address_impl # :nodoc: + @address_impl + end + + # Returns the name for the +Address+. + # + # ==== Examples + # + # puts "The address name is #{addr.name}." + # + def name; @address_impl.getName; end + + # Sets the name for the +Address+. + # + # ==== Examples + # + # addr.name = "my-new-queue" + # + def name=(name); @address_impl.setName name; end + + # Returns the subject for the +Address+. + # + # ==== Examples + # + # puts "The subject is #{addr.subject}." + # + def subject; @address_impl.getSubject; end + + # Sets the subject for the +Address+. + # + # ==== Examples + # + # addr.subject = "testing" + # + def subject=(subject); @address_impl.setSubject(subject); end + + # Returns the type for the +Address+. + # + # ==== Examples + # + # puts "The address is a #{address.address_type}." + # + #--- + # We cannot use "type" since that clashes with the Ruby object.type + # identifier. + def address_type; @address_impl.getType; end + + # Sets the type for the +Address+. + # + # The type of the address determines how +Sender+ and +Receiver+ objects + # are constructed for it. If no type is specified then it will be + # determined by querying the broker. + # + # ===== Options + # + # * type - the address type + # + def address_type=(type); @address_impl.setType(type); end + + # Returns the options. + def options; @address_impl.getOptions; end + + # Sets the options for the address. + # + # *NOTE:* See the class documentation for more details on options. + # + # ==== Examples + # + # addr.options = :create => :always + # + def options=(options = {}); @address_impl.setOptions(convert_options(options)); end + + def to_s # :nodoc: + @address_impl.str + end + + private + + def convert_options(options) + result = {} + options.each_pair {|key, value| result[key.to_s] = value.to_s} + + return result + end + + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/connection.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/connection.rb new file mode 100644 index 0000000000..12669bc947 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/connection.rb @@ -0,0 +1,162 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'cqpid' + +module Qpid + + module Messaging + + # Establishes a connection to a remote endpoint. + class Connection + + attr_reader :options # :nodoc: + + # Creates a connection object, but does not actually connect to + # the specified location. + # + # ==== Options + # + # :url - the URL for the broker (def. +"localhost"+) + # :options - connection options (def. +{}+) + # + # ==== Controlling Reconnect Behavior + # + # The following connection options can be used to configure + # the reconnection behavior for this connection. + # + # * :username + # * :password + # * :heartbeat + # * :tcp_nodelay + # * :sasl_mechanism + # * :sasl_service + # * :sasl_min_ssf + # * :sasl_max_ssf + # * :transport + # * :reconnect - +true+ or +false+; indicates wehtehr to attempt reconnections + # * :reconnect_timeout - the number of seconds to attempt reconnecting + # * :reconnect_limit - the number of retries before reporting failure + # * :reconnect_interval_min - initial delay, in seconds, before attempting a reconnection + # * :reconnect_interval_max - number of seconds to wait before additional reconnect attempts + # * :reconnect_interval - shorthand for setting both min and max values + # * :reconnect_urls - a list of alternate URLs to use for reconnection attempts + # + # ==== Examples + # + # conn = Qpid::Messaging::Connnection.new + # conn = Qpid::Messaging::Connection.new :url => "amqp:tcp:broker1.domain.com:5672" + # conn = Qpid::Messaging::Connection.new :options => {:username => "login", :password => "password"} + # + def initialize(opts = {}) + @url = opts[:url] || "localhost" + @options = convert_options(opts[:options] || {}) + @connection_impl = opts[:impl] || Cqpid::Connection.new(@url, @options) + end + + def connection_impl # :nodoc: + @connection_impl + end + + # Establishes the connection. + # + # ==== Examples + # + # conn.open unless conn.open? + # + def open + @connection_impl.open + end + + # Reports whether the connection is open. + # + # ==== Examples + # + # conn.close if conn.open? + # + def open?; true && !@connection_impl.nil? && @connection_impl.isOpen; end + + # Closes the connection. + def close; @connection_impl.close; end + + # Creates a new session. + # + # ==== Arguments + # + # * :name - specifies the name for this session + # * :transactional - if +true+ then a creates a transaction session (def. +false+) + # + # ==== Examples + # + # session = conn.create_session :name => "session1" + # session = conn.create_session :transaction => true + # + def create_session(args = {}) + name = args[:name] || "" + if open? + if args[:transactional] + session = @connection_impl.createTransactionalSession name + else + session = @connection_impl.createSession name + end + return Session.new(self, session) + else + raise RuntimeError.new "No connection available." + end + end + + # Returns a session for the specified session name. + # + # ==== Examples + # + # begin + # session = conn.session "mysession" + # rescue SessionNameException => error + # puts "No such session." + # end + # + def session name + begin + session_impl = @connection_impl.getSession name + Qpid::Messaging::Session.new self, session_impl if session_impl + rescue + raise Qpid::Messaging::SessionNameException.new "No such session: #{name}" + end + end + + # Returns the username used to authenticate with the connection. + def authenticated_username; @connection_impl.getAuthenticatedUsername if open?; end + + private + + def convert_options(options) + result = {} + unless options.nil? || options.empty? + options.each_pair {|key, value| result[key.to_s] = value.to_s} + end + + return result + end + + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/duration.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/duration.rb new file mode 100644 index 0000000000..e1ddd79cb6 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/duration.rb @@ -0,0 +1,95 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'cqpid' + +module Qpid + + module Messaging + + # A Duration represents a period of time in milliseconds + # + # It defines the following named values as symbols: + # + # [:FOREVER] + # The maximum integer value for the platform. Effectively this will wait + # forever. + # + # [:IMMEDIATE] + # An alias for 0 milliseconds. + # + # [:SECOND] + # An alias for 1,000 milliseconds. + # + # [:MINUTE] + # And alias for 60,000 millisecons. + # + class Duration + + # Creates a Duration with the specified length, in milliseconds. + # + # ==== Options + # + # * length - The duration in milliseconds. + # + # ==== Examples + # + # # Wait up to 10 seconds for an incoming message + # receiver.get Qpid::Messaging::Duration.new 10000 + # + def initialize length + @duration_impl = Cqpid::Duration.new length + end + + def duration_impl # :nodoc: + @duration_impl + end + + # Returns the period of time in milliseconds + # + # ==== Examples + # + # duration = Qpid::Messaging::Duration.new :length => 5000 + # puts "Waiting #{duration.milliseconds} ms for a message." + # msg = receiver.fetch duration + # + def milliseconds + @duration_impl.getMilliseconds + end + + def self.add_item(key, value) # :nodoc: + @hash ||= {} + @hash[key] = Duration.new value + end + + def self.const_missing(key) # :nodoc: + @hash[key] + end + + self.add_item :FOREVER, Cqpid::Duration.FOREVER.getMilliseconds + self.add_item :IMMEDIATE, Cqpid::Duration.IMMEDIATE.getMilliseconds + self.add_item :SECOND, Cqpid::Duration.SECOND.getMilliseconds + self.add_item :MINUTE, Cqpid::Duration.MINUTE.getMilliseconds + + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb new file mode 100644 index 0000000000..2f20fab18e --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/encoding.rb @@ -0,0 +1,60 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'cqpid' + +module Qpid + + module Messaging + + # Encodes the supplied content into the given message. + def self.encode content, message, encoding = nil + prepared = content + case content + when Hash + prepared = {} + content.each_pair do |key,value| + prepared[key.to_s] = value.to_s + end + Cqpid::encode prepared, message.message_impl + when Array + prepared = [] + content.each {|value| prepared << value.to_s} + Cqpid::encode prepared, message.message_impl + end + end + + # Decodes and returns the message's content. + def self.decode(message, content_type = nil) + content_type = message.content_type unless content_type + + case content_type + when "amqp/map" + Cqpid.decodeMap message.message_impl + when "amqp/list" + Cqpid.decodeList message.message_impl + end + + message.content + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/errors.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/errors.rb new file mode 100644 index 0000000000..c98eb1ac12 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/errors.rb @@ -0,0 +1,33 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +module Qpid + + module Messaging + + class KeyError < RuntimeError; end + + class SessionNameException < Exception + def initialize(msg); super(msg); end + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb new file mode 100644 index 0000000000..edef0ac2a0 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb @@ -0,0 +1,368 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'cqpid' + +module Qpid + + module Messaging + + # A +Message+ represents an routable piece of information. + # + # The content for a message is automatically encoded and decoded. + # + class Message + + # Creates a new instance of +Message+. + # + # ==== Options + # + # * :content - The content. + # + # ==== Examples + # + # message = Qpid::Messaging::Message.new :content => "This is a message." + # + def initialize(args = {}) + @message_impl = (args[:impl] if args[:impl]) || nil + @message_impl = Cqpid::Message.new if @message_impl.nil? + @content = nil + args = {} if args.nil? + self.content = args[:content] if args[:content] + end + + def message_impl # :nodoc: + @message_impl + end + + # Sets the address to which replies should be sent for the +Message+. + # + # *NOTE:* The address must be an instance of Address. + # + # ==== Options + # + # * address - an instance of +Address+ + # + # ==== Examples + # + # msg.reply_to = Qpid:Messaging::Address.new "my-responses" + # + def reply_to=(address) + raise ArgumentError, "Agument must be an Address" unless address.is_a? Qpid::Messaging::Address + @message_impl.setReplyTo address.address_impl + end + + # Returns the reply to address for the +Message+. + # + def reply_to + address_impl = @message_impl.getReplyTo + # only return an address if a reply to was specified + Qpid::Messaging::Address.new(nil, nil, nil, nil, address_impl) if address_impl + end + + # Sets the subject for the +Message+. + # + # ==== Options + # + # * subject - the subject + # + # ==== Examples + # + # msg.subject = "mysubject" + # + def subject=(subject); @message_impl.setSubject subject; end + + # Returns the subject of the +Message+. + # + # ==== Options + # + # puts "The subject is #{msg.subject}" + # + def subject; @message_impl.getSubject; end + + # Sets the content type for the +Message+. + # + # This should be set by the sending applicaton and indicates to + # recipients of the message how to interpret or decode the content. + # + # By default, only dictionaries and maps are automatically given a content + # type. If this content type is replaced then retrieving the content will + # not behave correctly. + # + # ==== Options + # + # * content_type - the content type. + # + def content_type=(content_type); @message_impl.setContentType content_type; end + + # Returns the content type for the +Message+. + # + # ==== Examples + # + # case msg.content_type + # when "myapp/image" + # ctl.handle_image msg + # end + # when "myapp/audio" + # ctl.handle_audio msg + # end + # end + # + def content_type; @message_impl.getContentType; end + + # Sets the message id. + # + # *NOTE:* this field must be a UUID type currently. A non-UUID value will + # be converted to a zero UUID, though a blank ID will be left untouched. + # + # ==== Options + # + # * id - the id + # + # ==== Examples + # + # + def message_id=(message_id); @message_impl.setMessageId message_id.to_s; end + + # Returns the message id. + # + # See +message_id=+ for details. + def message_id; @message_impl.getMessageId; end + + # Sets the user id for the +Message+. + # + # This should in general be the user-id which was used when authenticating + # the connection itself, as the messaging infrastructure will verify + # this. + # + # See +Qpid::Messaging::Connection.authenticated_username+ + # + # *NOTE:* If the id is not a +String+ then the id is set using + # the object's string representation. + # + # ==== Options + # + # * id - the id + # + def user_id=(user_id); @message_impl.setUserId user_id; end + + # Returns the user id for the +Message+. + # + # See +user_id=+ for details. + # + def user_id; @message_impl.getUserId; end + + # Sets the correlation id of the +Message+. + # + # The correlation id can be used as part of a protocol for message + # exchange patterns; e.g., a requestion-response pattern might require + # the correlation id of the request and the response to match, or it + # might use the message id of the request as the correlation id on + # the response + # + # *NOTE:* If the id is not a +String+ then the id is setup using + # the object's string representation. + # + # ==== Options + # + # * id - the id + # + def correlation_id=(correlation_id); @message_impl.setCorrelationId correlation_id; end + + # Returns the correlation id of the +Message+. + # + # *NOTE:* See +correlation_id=+ for details. + # + def correlation_id; @message_impl.getCorrelationId; end + + # Sets the priority of the +Message+. + # + # This may be used by the messaging infrastructure to prioritize + # delivery of messages with higher priority. + # + # *NOTE:* If the priority is not an integer type then it is set using + # the object's integer representation. If the integer value is greater + # than 8-bits then only the first 8-bits are used. + # + # ==== Options + # + # * priority - the priority + # + def priority=(priority); @message_impl.setPriority priority; end + + # Returns the priority for the +Message+. + # + def priority; @message_impl.getPriority; end + + # Sets the time-to-live in milliseconds. + # + # ==== Options + # + # * duration - the number of milliseconds + # + def ttl=(duration) + if duration.is_a? Qpid::Messaging::Duration + @message_impl.setTtl duration.duration_impl + else + @message_impl.setTtl Cqpid::Duration.new duration.to_i + end + end + + # Returns the time-to-live in milliseconds. + def ttl; Qpid::Messaging::Duration.new @message_impl.getTtl.getMilliseconds; end + + # Sets the durability of the +Message+. + # + # This is a hint to the messaging infrastructure that the message + # should be persisted or otherwise stored. This helps to ensure + # that th emessage is not lost during to failures or a shutdown. + # + # ==== Options + # + # * durable - the durability flag (def. false) + # + def durable=(durable); @message_impl.setDurable durable; end + + # Returns the durability for the +Message+. + # + def durable; @message_impl.getDurable; end + + # This is a hint to the messaging infrastructure that if de-duplication + # is required, that this message should be examined to determine if it + # is a duplicate. + # + # ==== Options + # + # * redelivered - sets the redelivered state (def. false) + # + # ==== Examples + # + # # processed is an array of processed message ids + # msg.redelivered = true if processed.include? msg.message_id + # + def redelivered=(redelivered); @message_impl.setRedelivered redelivered; end + + # Returns whether the +Message+ has been marked as redelivered. + # + def redelivered; @message_impl.getRedelivered; end + + # Returns all named properties. + # + # *NOTE:* It is recommended to use the []= method for + # retrieving and setting properties. Using this method may + # result in non-deterministic behavior. + # + def properties; @message_impl.getProperties; end + + # Returns the value for the named property. + # + # ==== Options + # + # * name - the property name + # + # ==== Examples + # + # # use of message properties to mark a message as digitally signed + # verify(msg) if msg[:signed] + # + def [](key); self.properties[key.to_s]; end + + # Assigns a value to the named property. + # + # *NOTE:* Both the key or the value may be a symbol, but they will + # both be converted to a +String+ for ease of transport. + # + # ==== Options + # + # * name - the property name + # * value - the property value + def []=(key, value); @message_impl.setProperty(key.to_s, value.to_s); end + + # Sets the content for the +Message+. + # + # Content is automatically encoded for Array and Hash types. Other types + # need to set their own content types (via +content_type+) in order to + # specify how recipients should process the content. + # + # ==== Options + # + # * content - the content + # + # ==== Examples + # + # msg.content = "This is a simple message." # a simple message + # msg.content = {:foo => :bar} # content is automatically encoded + # + def content=(content) + content_type = nil + @content = content + case @content + when Hash + content_type = "amqp/map" + new_content = {} + content.each_pair{|key, value| new_content[key.to_s] = value.to_s} + @content = new_content + when Array + new_content = [] + content_type = "amqp/list" + content.each {|element| new_content << element.to_s} + @content = new_content + end + if content_type.nil? + @message_impl.setContent @content + else + Qpid::Messaging.encode @content, self, content_type + end + end + + # Returns the content of the +Message+. + # + # Content is automatically decoded based on the specified content type. + # If the content type is application-specific, then no decoding is + # performed and the content is returnedas a +String+ representation. + # + # For example, if an array of integers are sent, then the receiver will + # find the message content to be an array of String objects, where each + # String is a representation of the sent integer value. + # + def content + if @content.nil? + @content = @message_impl.getContent + + # decode the content is necessary if it + # has an encoded content type + if ["amqp/list", "amqp/map"].include? @message_impl.getContentType + @content = Qpid::Messaging.decode(self, + @message_impl.getContentType) + end + + end + @content + end + + # Returns the content's size. + # + def content_size; @message_impl.getContentSize; end + + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/receiver.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/receiver.rb new file mode 100644 index 0000000000..0ce16309ed --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/receiver.rb @@ -0,0 +1,186 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'cqpid' + +require 'qpid/duration' + +module Qpid + + module Messaging + + # Receiver is the entity through which messages are received. + # + # An instance of Receiver can only be created using an active (not + # previously closed) Session. + # + # ==== Example + # + # conn = Qpid::Messaging::Connection.new :url => "mybroker:5762" + # conn.open + # session = conn.create_session + # receiver = session.create_receiver "my-sender-queue" + class Receiver + + def initialize(session, receiver_impl) # :nodoc: + @session = session + @receiver_impl = receiver_impl + end + + def receiver_impl # :nodoc: + @receiver_impl + end + + # Retrieves a message from the local queue, or waits for up to + # the duration specified for one to become available. + # + # If a block is given, then it will be invaked after the next message + # is received or the call times out, passing in the message or nil + # respectively. + # + # ==== Options + # * duration - the timeout to wait (def. Duration::FOREVER) + # + # ==== Examples + # + # msg = rcvr.get # Uses the default timeout of forever + # + # msg = rcvr.get Qpid::Messaging::Duration::IMMEDIATE # returns a message or exits immediately + # + # # passes in a block to handle the received message + # rcvr.get Qpid::Messaging::Duration::SECOND do |message| + # if message.nil? + # puts "No message was received." + # else + # puts "Received this message: #{message.content}" + # end + # end + def get(duration = Qpid::Messaging::Duration::FOREVER) + message_impl = @receiver_impl.get duration.duration_impl + create_message_wrapper message_impl unless message_impl.nil? + end + + # Retrieves a message from the receiver's subscription, or waits + # for up to the duration specified for one to become available. + # + # If a block is given, then it will be invaked after the next message + # is received or the call times out, passing in the message or nil + # respectively. + # + # ==== Options + # * duration - the timeout to wait (def. Duration::FOREVER) + # + # ==== Examples + # + # msg = rcvr.fetch # Uses the default timeout of forever + # + # msg = rcvr.fetch Qpid::Messaging::Duration::IMMEDIATE # returns a message or exits immediately + # + # # passes in a block to handle the received message + # rcvr.fetch Qpid::Messaging::Duration::SECOND do |message| + # if message.nil? + # puts "No message was received." + # else + # puts "Received this message: #{message.content}" + # end + # end + def fetch(duration = Qpid::Messaging::Duration::FOREVER) + message_impl = @receiver_impl.fetch duration.duration_impl + create_message_wrapper message_impl unless message_impl.nil? + end + + # Sets the capacity for this +Receiver+. + # + # ==== Options + # + # * capacity - the capacity + # + # ==== Examples + # + # receiver.capacity = 50 # sets the incoming capacity to 50 messages + # + def capacity=(capacity); @receiver_impl.setCapacity capacity; end + + # Returns the capacity. + # + # + # The capacity is the numnber of incoming messages that can be held + # locally before being fetched. + # + # ==== Examples + # + # puts "The receiver can hold #{rcv.capacity} messages." + # + def capacity; @receiver_impl.getCapacity; end + + # Returns the number of slots for receiving messages. + # + # This differs from +capacity+ in that it is the available slots in + # the capacity for holding incoming messages, where available <= capacity. + # + # ==== Examples + # + # puts "You can receive #{rcv.available} messages before blocking." + # + def available; @receiver_impl.getAvailable; end + + # Returns the number of messages that have been received and acknowledged + # but whose acknowledgements have not been confirmed by the sender. + # + # ==== Examples + # + # puts "You have #{rcv.unsettled} messages to be confirmed." + # + def unsettled; @receiver_impl.getUnsettled; end + + # Closes this +Receiver+. + # + # This does not affect the +Session+. + def close; @receiver_impl.close; end + + # Returns whether the receiver is closed. + # + # ==== Examples + # + # recv.close unless recv.closed? + # + def closed?; @receiver_impl.isClosed; end + + # Returns the name of this +Receiver+. + # + # ==== Examples + # + # puts "Receiver: #{recv.name}" + def name; @receiver_impl.getName; end + + # Returns the Session for this +Receiver+. + def session; @session; end + + private + + def create_message_wrapper message_impl # :nodoc: + Qpid::Messaging::Message.new(:impl => message_impl) + end + + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/sender.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/sender.rb new file mode 100644 index 0000000000..97227622f5 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/sender.rb @@ -0,0 +1,152 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +module Qpid + + module Messaging + + # Sender is the entity through which messages sent. + # + # An instance of Sender can only be created using an active (not previously + # closed) Session. + # + # ==== Examples + # + # conn = Qpid::Messaging::Connection.new :url => "mybroker:5762" + # conn.open + # session = conn.create_session + # sender = session.create_session "my-sender-queue;{create:always}" + class Sender + + def initialize(session, sender_impl) # :nodoc: + @session = session + @sender_impl = sender_impl + end + + def sender_impl # :nodoc: + @sender_impl + end + + # Sends a message. + # + # If a block is given, then it will be invoked after the message + # is sent. + # + # ==== Options + # + # * message - The message to send. + # * :sync - See note below on synching. + # + # ==== Synching + # + # If :sync => true, then the call will block until the broker confirms + # receipt of the message. Otherwise it will only block for available + # capacity; i.e., until pending is equal to capacity. + # + # ==== Examples + # + # sender.send message do |message| + # puts "Message sent: #{message.content}" + # end + # + def send(message, args = {}, &block) + sync = args[:sync] || false + @sender_impl.send message.message_impl, sync + block.call message unless block.nil? + end + + # Closes this +Sender+. + # + # This does not affect the +Session+. + def close; @sender_impl.close; end + + # Returns the human-readable name for this +Sender+. + # + # ==== Examples + # + # puts "Sender: #{sender.name}" + # + def name; @sender_impl.getName; end + + # Sets the capacity for this +Sender+. + # + # The capacity is the number of outgoing messages that can be held + # pending confirmation or receipt by the broker. + # + # ==== Options + # + # * capacity - the capacity + # + # ==== Examples + # + # sender.capacity = 50 # sets the outgoing capacity to 50 messages + # + def capacity=(capacity); @sender_impl.setCapacity capacity; end + + # Returns the capacity. + # + # The capacity is the total number of outgoing messages that can be + # sent before a called to +send+ begins to block by default. + # + # ==== Examples + # + # puts "You can send a maximum of #{sender.capacity} messages." + # + def capacity; @sender_impl.getCapacity; end + + # Returns the number of messages sent that are pending receipt + # confirmation by the broker. + # + # ==== Examples + # + # if sender.unsettled > 0 + # puts "There are #{sender.unsettled} messages pending." + # end + # + def unsettled; @sender_impl.getUnsettled; end + + # Returns the available slots for sending messages. + # + # This differs from +capacity+ in that it is the available slots in + # the senders capacity for holding outgoing messages. The difference + # between capacity and available is the number of messages that + # have not been delivered yet. + # + # ==== Examples + # + # puts "You can send #{sender.available} messages before blocking." + # + def available + @sender_impl.getAvailable + end + + # Returns the +Session+ for this sender. + # + # ==== Examples + # + # recv.session.close if done + # + def session; @session; end + + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/session.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/session.rb new file mode 100644 index 0000000000..feb8aa5bb4 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/session.rb @@ -0,0 +1,271 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +require 'cqpid' + +require 'qpid/errors' + +module Qpid + + module Messaging + + # A Session represents a distinct conversation between end points. + class Session + + def initialize(connection, session) # :nodoc: + @connection = connection + @session_impl = session + @senders = Hash.new + @receivers = Hash.new + end + + def session_impl # :nodoc: + @session_impl + end + + # Returns the +Connection+ associated with this session. + def connection + @connection + end + + # Creates a new endpoint for sending messages. + # + # The +address+ can either be an instance +Address+ or else a + # string that describes an address endpoint. + # + # ==== Arguments + # + # * +address+ The end point address. + # + # ==== Examples + # + # sender = session.create_sender "my-queue;{create:always}" + # + def create_sender(address) + _address = address + + if address.class == Qpid::Messaging::Address + _address = address.address_impl + end + + sender_impl = @session_impl.createSender(_address) + sender_name = sender_impl.getName + + @senders[sender_name] = Qpid::Messaging::Sender.new(self, sender_impl) + + @senders[sender_name] + end + + # Retrieves the +Sender+ with the specified name. + # + # The +Sender+ must have been previously created using + # the +create_sender+ method. + # + # ==== Arguments + # + # * +name+ The +Sender+ name. + # + # ==== Examples + # + # sender = session.sender "my-queue" + # + def sender(name) + raise Qpid::Messaging::KeyError, "No such sender: #{name}" unless @senders.has_key? name + + @senders[name] + end + + # Creates a new endpoint for receiving messages. + # + # The +address+ can either be an instance +Address+ or else a + # string that describes an address endpoint. + # + # ==== Arguments + # + # * +address+ The end point address. + # + # ==== Examples + # + # receiver = session.create_receiver "my-queue" + # + def create_receiver(address) + result = nil + receiver_impl = nil + + if address.class == Qpid::Messaging::Address + address_impl = address.address_impl + receiver_impl = @session_impl.createReceiver address_impl + else + receiver_impl = @session_impl.createReceiver(address) + end + + receiver_name = receiver_impl.getName + + @receivers[receiver_name] = Qpid::Messaging::Receiver.new self, receiver_impl + + @receivers[receiver_name] + end + + # Retrieves the +Receiver+ with the specified name. + # + # The +Receiver+ must have been previously created using + # the +create_receiver+ method. + # + # ==== Arguments + # + # * +name+ The +Receiver+ name. + # + # ==== Examples + # + # receiver = session.receiver "my-queue" + # + def receiver(name) + raise Qpid::Messaging::KeyError, "No such receiver: #{name}" unless @receivers.has_key? name + + @receivers[name] + end + + # Closes the +Session+ and all associated +Sender+ and +Receiver+ instances. + # + # NOTE: All +Session+ instances for a +Connection+ are closed when the + # +Connection+ is closed. + def close; @session_impl.close; end + + # Commits any pending transactions for a transactional session. + def commit; @session_impl.commit; end + + # Rolls back any uncommitted transactions on a transactional session. + def rollback; @session_impl.rollback; end + + # Acknowledges one or more outstanding messages that have been received + # on this session. + # + # ==== Arguments + # + # * :message - if specified, then only the +Message+ specified is acknowledged + # * :sync - if true then the call will block until processed by the server (def. false) + # + # ==== Examples + # + # session.acknowledge # acknowledges all received messages + # session.acknowledge :message => message # acknowledge one message + # session.acknowledge :sync => true # blocks until the call completes + # + #-- + # TODO: Add an optional block to be used for blocking calls. + #++ + def acknowledge(args = {}) + sync = args[:sync] || false + message = args[:message] if args[:message] + + unless message.nil? + @session_impl.acknowledge message.message_impl, sync + else + @session_impl.acknowledge sync + end + end + + # Rejects the specified message. A rejected message will not be + # redelivered. + # + # NOTE: A message cannot be rejected once it has been acknowledged. + def reject(message); @session_impl.reject message.message_impl; end + + # Releases the message, which allows the broker to attempt to + # redeliver it. + # + # NOTE: A message connot be released once it has been acknowled. + def release(message); @session_impl.release message.message_impl; end + + # Requests synchronization with the server. + # + # ==== Arguments + # + # * :block - if true then the call blocks until the server acknowledges it (def. false) + # + #-- + # TODO: Add an optional block to be used for blocking calls. + #++ + def sync(args = {}) + block = args[:block] || false + @session_impl.sync block + end + + # Returns the total number of receivable messages, and messages already + # received, by +Receiver+ instances associated with this +Session+. + def receivable; @session_impl.getReceivable; end + + # Returns the number of messages that have been acknowledged by this session + # whose acknowledgements have not been confirmed as processed by the server. + def unsettled_acks; @session_impl.getUnsettledAcks; end + + # Fetches the +Receiver+ for the next message. + # + # ==== Arguments + # + # * timeout - time to wait for a +Receiver+ before timing out + # + # ==== Examples + # + # recv = session.next_receiver # wait forever for the next +Receiver+ + # # execute a block on the next receiver + # session.next_receiver do |recv| + # msg = recv.get + # puts "Received message: #{msg.content}" + # end + def next_receiver(timeout = Qpid::Messaging::Duration::FOREVER, &block) + receiver_impl = @session_impl.nextReceiver(timeout.duration_impl) + + unless receiver_impl.nil? + recv = Qpid::Messaging::Receiver.new self, receiver_impl + block.call recv unless block.nil? + end + + return recv + end + + # Returns true if there were exceptions on this session. + # + # ==== Examples + # + # puts "There were session errors." if @session.errors? + def errors?; @session_impl.hasError; end + + # If the +Session+ has been rendered invalid due to some exception, + # this method will result in that exception being raised. + # + # If none have occurred, then no exceptions are raised. + # + # ==== Examples + # + # if @session.errors? + # begin + # @session.errors + # rescue Exception => error + # puts "An error occurred: #{error}" + # end + # end + def errors; @session_impl.checkError; end + + end + + end + +end + diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/version.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/version.rb new file mode 100644 index 0000000000..737f021006 --- /dev/null +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/version.rb @@ -0,0 +1,31 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +module Qpid #:nodoc: + + module Version + + NUMBERS = [MAJOR = 0, + MINOR = 17, + BUILD = 0] + end + + VERSION = Version::NUMBERS.join('.') + +end diff --git a/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb b/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb index 90084963f4..865e60e0e2 100644 --- a/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb +++ b/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb @@ -17,5 +17,4 @@ # under the License. # -require 'qpid' -require 'cqpid' +require 'qpid_messaging' -- cgit v1.2.1