You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mc...@apache.org on 2013/07/30 22:44:22 UTC
svn commit: r1508619 - in /qpid/proton/trunk: examples/messenger/ruby/
proton-c/bindings/ruby/ proton-c/bindings/ruby/lib/qpid_proton/
proton-c/bindings/ruby/spec/qpid/proton/
Author: mcpierce
Date: Tue Jul 30 20:44:21 2013
New Revision: 1508619
URL: http://svn.apache.org/r1508619
Log:
PROTON-369: Add properties field to Qpid:Proton::Message
Provides Rspec tests as well as updates the send and recv examples to
use properties.
Modified:
qpid/proton/trunk/examples/messenger/ruby/recv.rb
qpid/proton/trunk/examples/messenger/ruby/send.rb
qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog
qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb
qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb
qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb
Modified: qpid/proton/trunk/examples/messenger/ruby/recv.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/examples/messenger/ruby/recv.rb?rev=1508619&r1=1508618&r2=1508619&view=diff
==============================================================================
--- qpid/proton/trunk/examples/messenger/ruby/recv.rb (original)
+++ qpid/proton/trunk/examples/messenger/ruby/recv.rb Tue Jul 30 20:44:21 2013
@@ -73,6 +73,7 @@ loop do
subject = msg.subject || "(no subject)"
puts "Subject: #{subject}"
puts "Content: #{body}"
+ puts "Properties: #{msg.properties}"
end
end
Modified: qpid/proton/trunk/examples/messenger/ruby/send.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/examples/messenger/ruby/send.rb?rev=1508619&r1=1508618&r2=1508619&view=diff
==============================================================================
--- qpid/proton/trunk/examples/messenger/ruby/send.rb (original)
+++ qpid/proton/trunk/examples/messenger/ruby/send.rb Tue Jul 30 20:44:21 2013
@@ -43,8 +43,10 @@ msg = Qpid::Proton::Message.new
messages.each do |message|
msg.address = options[:address]
- msg.subject = "The time is #{Time.new}"
+ msg.subject = "How are you?"
msg.content = message
+ msg["sent"] = Time.new
+ msg["hostname"] = ENV["HOSTNAME"]
begin
messenger.put(msg)
rescue Qpid::Proton::ProtonError => error
Modified: qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog?rev=1508619&r1=1508618&r2=1508619&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/ChangeLog Tue Jul 30 20:44:21 2013
@@ -5,6 +5,7 @@ version 0.5:
- Messenger.receive can accept a negative maximum
- When testing bad subscribe attempts, tests now use a random string.
* Fixed encoding decimal128 values.
+ * Added properties field to Qpid::Proton::Message.
version 0.4:
* No language-specific features developed in this release.
Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb?rev=1508619&r1=1508618&r2=1508619&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/message.rb Tue Jul 30 20:44:21 2013
@@ -36,12 +36,46 @@ module Qpid
#
def decode(encoded)
check(Cproton.pn_message_decode(@impl, encoded, encoded.length))
+
+ post_decode
+ end
+
+ def post_decode # :nodoc:
+ # decode elements from the message
+ @properties = nil
+ props = Qpid::Proton::Data.new(Cproton::pn_message_properties(@impl))
+ if props.next
+ @properties = props.type.get(props)
+ end
+ end
+
+ # Encodes the message.
+ def encode
+ pre_encode
+ size = 16
+ loop do
+ error, data = Cproton::pn_message_encode(@impl, size)
+ if error == Qpid::Proton::Error::OVERFLOW
+ size *= 2
+ else
+ check(error)
+ return data
+ end
+ end
+ end
+
+ def pre_encode # :nodoc:
+ # encode elements from the message
+ props = Qpid::Proton::Data.new(Cproton::pn_message_properties(@impl))
+ props.clear
+ Qpid::Proton::Mapping.for_class(@properties.class).put(props, @properties) unless @properties.empty?
end
# Creates a new +Message+ instance.
def initialize
@impl = Cproton.pn_message
ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
+ @properties = {}
end
# Invoked by garbage collection to clean up resources used
@@ -438,6 +472,41 @@ module Qpid
Cproton.pn_message_get_reply_to_group_id(@impl)
end
+ # Returns the list of property names for associated with this message.
+ #
+ # ==== Examples
+ #
+ # msg.properties.each do |name|
+ # end
+ #
+ def properties
+ @properties
+ end
+
+ # Assigns the value given to the named property.
+ #
+ # ==== Arguments
+ #
+ # * name - the property name
+ # * value - the property value
+ #
+ def []=(name, value)
+ @properties[name] = value
+ end
+
+ # Retrieves the vaue for the specified property name. If not found, then
+ # it returns nil.
+ #
+ def [](name)
+ @properties[name]
+ end
+
+ # Deletes the named property.
+ #
+ def delete_property(name)
+ @properties.delete(name)
+ end
+
private
def check(err) # :nodoc:
Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb?rev=1508619&r1=1508618&r2=1508619&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb Tue Jul 30 20:44:21 2013
@@ -196,6 +196,8 @@ module Qpid
def put(message)
raise TypeError.new("invalid message: #{message}") if message.nil?
raise ArgumentError.new("invalid message type: #{message.class}") unless message.kind_of?(Message)
+ # encode the message first
+ message.pre_encode
check_for_error(Cproton.pn_messenger_put(@impl, message.impl))
end
@@ -218,6 +220,7 @@ module Qpid
def get(msg = nil)
msg = Qpid::Proton::Message.new if msg.nil?
check_for_error(Cproton.pn_messenger_get(@impl, msg.impl))
+ msg.post_decode unless msg.nil?
return msg
end
Modified: qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb?rev=1508619&r1=1508618&r2=1508619&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/message_spec.rb Tue Jul 30 20:44:21 2013
@@ -417,6 +417,56 @@ module Qpid
@message.content.should eq(content)
end
+ it "has properties" do
+ @message.should respond_to(:properties)
+ @message.should respond_to("[]".to_sym)
+ @message.should respond_to("[]=".to_sym)
+
+ @message.properties.should be_kind_of({}.class)
+ end
+
+ it "can set properties" do
+ name = random_string(16)
+ value = random_string(128)
+
+ @message[name] = value
+ @message[name].should eq(value)
+ end
+
+ it "can update properties" do
+ name = random_string(16)
+ value = random_string(128)
+
+ @message[name] = value
+ @message[name].should eq(value)
+
+ value = random_string(128)
+ @message[name] = value
+ @message[name].should eq(value)
+ end
+
+ it "can hold a null property" do
+ name = random_string(16)
+ value = random_string(128)
+
+ @message[name] = value
+ @message[name].should eq(value)
+
+ @message[name] = nil
+ @message[name].should be_nil
+ end
+
+ it "can delete a property" do
+ name = random_string(16)
+ value = random_string(128)
+
+ @message[name] = value
+ @message[name].should eq(value)
+
+ @message.delete_property(name)
+ @message.properties.keys.should_not include(name)
+ end
+
end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org