lib/mq/rpc.rb in amqp-0.7.0.pre vs lib/mq/rpc.rb in amqp-0.7.0
- old
+ new
@@ -1,5 +1,7 @@
+# encoding: utf-8
+
class MQ
# Basic RPC (remote procedure call) facility.
#
# Needs more detail and explanation.
#
@@ -38,11 +40,11 @@
# 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
+ def initialize(mq, queue, obj = nil)
@mq = mq
@mq.rpcs[queue] ||= self
if obj
@obj = case obj
@@ -52,11 +54,11 @@
(::Class.new do include(obj) end).new
else
obj
end
- @mq.queue(queue).subscribe(:ack=>true){ |info, request|
+ @mq.queue(queue).subscribe(:ack => true) { |info, request|
method, *args = ::Marshal.load(request)
ret = @obj.__send__(method, *args)
info.ack
@@ -65,11 +67,11 @@
end
}
else
@callbacks ||= {}
# XXX implement and use queue(nil)
- @queue = @mq.queue(@name = "random identifier #{::Kernel.rand(999_999_999_999)}", :auto_delete => true).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)
@@ -88,10 +90,10 @@
# # arguments to publish them to the remote
# client[:now] = Time.now
# ....
# end
#
- def method_missing meth, *args, &blk
+ def method_missing(meth, *args, &blk)
# XXX use uuids instead
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