diff options
10 files changed, 77 insertions, 18 deletions
diff --git a/qpid/cpp/bindings/qpid/ruby/examples/client.rb b/qpid/cpp/bindings/qpid/ruby/examples/client.rb index f400acfd13..9e22bade0d 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/client.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/client.rb @@ -40,7 +40,7 @@ if __FILE__ == $0 request.reply_to = response_queue sender.send request response = receiver.fetch - puts "#{request.content} -> #{response.content}" + puts "#{request.content_object} -> #{response.content_object}" end connection.close diff --git a/qpid/cpp/bindings/qpid/ruby/examples/drain.rb b/qpid/cpp/bindings/qpid/ruby/examples/drain.rb index 8e506ea5cd..6bf3d93c36 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/drain.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/drain.rb @@ -93,11 +93,11 @@ begin message = receiver.fetch(options[:timeout]) print "Message(properties=" render_map message.properties - print ", content=" - if message.content_type == "amqp/map" - print "'#{render_map message.content}')" + print ", content_object=" + if message.content_object == "amqp/map" + print "'#{render_map message.content_object}')" else - print "'#{message.content}'" + print "'#{message.content_object}'" end print ")\n" session.acknowledge message diff --git a/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb b/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb index 1f4954dde9..1928d55408 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/hello_world.rb @@ -41,7 +41,7 @@ if __FILE__ == $0 # Now receive the message message = receiver.fetch Qpid::Messaging::Duration::SECOND - puts "#{message.content}" + puts "#{message.content_object}" session.acknowledge connection.close diff --git a/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb b/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb index 16704dd48e..9ff5f7eea0 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/map_receiver.rb @@ -44,7 +44,7 @@ begin receiver = session.create_receiver address message = receiver.fetch - content = message.content + content = message.content_object print "content-type:#{message.content_type}" print "{" diff --git a/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb b/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb index 1908774c31..f876bc5560 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/map_sender.rb @@ -23,7 +23,7 @@ require 'qpid_messaging' broker = ARGV[0] || "amqp:tcp:127.0.0.1:5672" address = ARGV[1] || "message_queue; {create: always}" -options = ARGV[2] || [] +options = ARGV[2] || {} connection = Qpid::Messaging::Connection.new :url => broker, :options => options connection.open @@ -34,18 +34,19 @@ begin message = Qpid::Messaging::Message.new content = { - :id => 987654321, + "id" => 987654321, :name => "Widget", :percent => 0.99, :colors => ["red", "green", "blue"] } - message.content = content + message.content_object = content sender.send message rescue Exception => error puts "Exception: #{error.message}" + puts error.backtrace end connection.close diff --git a/qpid/cpp/bindings/qpid/ruby/examples/server.rb b/qpid/cpp/bindings/qpid/ruby/examples/server.rb index a589bea799..8b21cb033b 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/server.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/server.rb @@ -36,12 +36,12 @@ if __FILE__ == $0 if !address.nil? sender = session.create_sender address - response = Qpid::Messaging::Message.new :content => request.content.upcase + response = Qpid::Messaging::Message.new :content => request.content_object.upcase sender.send response - puts "Processed request: #{request.content} -> #{response.content}" + puts "Processed request: #{request.content_object} -> #{response.content_object}" session.acknowledge else - puts "Error: no reply address specified for request: #{request.content}" + puts "Error: no reply address specified for request: #{request.content_object}" session.reject request end end diff --git a/qpid/cpp/bindings/qpid/ruby/examples/spout.rb b/qpid/cpp/bindings/qpid/ruby/examples/spout.rb index 6a0751e682..ab5ecf47a2 100644 --- a/qpid/cpp/bindings/qpid/ruby/examples/spout.rb +++ b/qpid/cpp/bindings/qpid/ruby/examples/spout.rb @@ -137,12 +137,12 @@ options[:properties].each_key {|key| message[key] = options[:properties][key]} (1..options[:count]).each do |count| if !options[:mapped].keys.empty? - message.content = options[:mapped] + message.content_object = options[:mapped] elsif options[:content] - message.content = options[:content] + message.content_object = options[:content] end message.durable = options[:durable] - message.content = options[:content] unless options[:content].nil? + message.content_object = options[:content] unless options[:content].nil? message.properties["spout-id"] = "#{count}" message.reply_to = options[:replyto] unless options[:replyto].nil? || options[:replyto].empty? sender.send message diff --git a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb index e167800455..58205bdcbc 100644 --- a/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb +++ b/qpid/cpp/bindings/qpid/ruby/lib/qpid_messaging/message.rb @@ -39,9 +39,8 @@ module Qpid 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] + self.content_object = args[:content] if args[:content] end def message_impl # :nodoc: @@ -345,6 +344,29 @@ module Qpid # Returns the content's size in bytes. def content_size; @message_impl.getContentSize; end + # Sets the message content. + # + # ==== Options + # + # * +content+ - the content + # + # ==== Examples + # + # # set a simple content for a message + # msg.content_object = "This is a simple message." + # # sets content that is automatically encoded + # msg.content_object = {:foo => :bar} + # + def content_object=(content) + @message_impl.setContentObject(Qpid::Messaging.stringify(content)) + end + + # Returns the content of the +Message+. + # + def content_object + @message_impl.getContentObject() + end + end end diff --git a/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb b/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb index be19b3591e..3581174548 100644 --- a/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb +++ b/qpid/cpp/bindings/qpid/ruby/spec/qpid_messaging/message_spec.rb @@ -64,6 +64,36 @@ module Qpid content.should == "My content" end + it "should store and retrieve string content properly" do + content = random_string(64) + + @message.content_object = content + @message.content_object.should == content + end + + it "should store and retrieve numeric content properly" do + content = rand(65536) + + @message.content_object = content + @message.content_object.should == content + end + + it "should store and retrieve map content properly" do + content = {} + (1..rand(128)).each { content["#{random_string(64)}"] = "#{random_string(64)}" } + + @message.content = content + @message.content.should eq content + end + + it "should store and retrieve list content properly" do + content = [] + (1..rand(128)).each { content << "#{random_string(64)}" } + + @message.content = content + @message.content.should eq content + end + it "should properly encode a map when created" do message = Qpid::Messaging::Message.new :content => {"foo" => "bar"} diff --git a/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb b/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb index 865e60e0e2..cf1b3b25f9 100644 --- a/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb +++ b/qpid/cpp/bindings/qpid/ruby/spec/spec_helper.rb @@ -18,3 +18,9 @@ # require 'qpid_messaging' + +# Generates a random string of the specified length +def random_string(length = 8) + (0...length).map{65.+(rand(25)).chr}.join +end + |