lib/mq/rpc.rb in brontes3d-amqp-0.6.4.3 vs lib/mq/rpc.rb in brontes3d-amqp-0.6.7.1
- old
+ new
@@ -28,18 +28,18 @@
# during this setup. The passed queue is automatically subscribed to so
# it passes all messages (and their arguments) to the object.
#
# Marshalling and unmarshalling the objects is handled internally. This
# marshalling is subject to the same restrictions as defined in the
- # Marshal[http://ruby-doc.org/core/classes/Marshal.html] standard
+ # Marshal[http://ruby-doc.org/core/classes/Marshal.html] standard
# library. See that documentation for further reference.
#
- # When the optional object is not passed, the returned rpc reference is
- # used to send messages and arguments to the queue. See #method_missing
- # which does all of the heavy lifting with the proxy. Some client
- # elsewhere must call this method *with* the optional block so that
- # there is a valid destination. Failure to do so will just enqueue
+ # When the optional object is not passed, the returned rpc reference is
+ # used to send messages and arguments to the queue. See #method_missing
+ # which does all of the heavy lifting with the proxy. Some client
+ # elsewhere must call this method *with* the optional block so that
+ # there is a valid destination. Failure to do so will just enqueue
# marshalled messages that are never consumed.
#
def initialize mq, queue, obj = nil
@mq = mq
@mq.rpcs[queue] ||= self
@@ -51,11 +51,11 @@
when ::Module
(::Class.new do include(obj) end).new
else
obj
end
-
+
@mq.queue(queue).subscribe(:ack=>true){ |info, request|
method, *args = ::Marshal.load(request)
ret = @obj.__send__(method, *args)
info.ack
@@ -65,11 +65,11 @@
end
}
else
@callbacks ||= {}
# XXX implement and use queue(nil)
- @queue = @mq.queue(@name = "random identifier #{::Kernel.rand(999_999_999_999)}").subscribe{|info, msg|
+ @queue = @mq.queue(@name = "random identifier #{::Kernel.rand(999_999_999_999)}", :auto_delete => true).subscribe{|info, msg|
if blk = @callbacks.delete(info.message_id)
blk.call ::Marshal.load(msg)
end
}
@remote = @mq.queue(queue)
@@ -95,6 +95,6 @@
message_id = "random message id #{::Kernel.rand(999_999_999_999)}"
@callbacks[message_id] = blk if blk
@remote.publish(::Marshal.dump([meth, *args]), :reply_to => blk ? @name : nil, :message_id => message_id)
end
end
-end
\ No newline at end of file
+end