Daijiro MORI
null+****@clear*****
Thu Sep 19 20:25:15 JST 2013
Daijiro MORI 2013-09-19 20:25:15 +0900 (Thu, 19 Sep 2013) New Revision: 06019569035d5a22e25020ef2787874e3da7a384 https://github.com/droonga/fluent-plugin-droonga/commit/06019569035d5a22e25020ef2787874e3da7a384 Message: Set type field to "type.result" for replying messages. Modified files: lib/droonga/executor.rb Modified: lib/droonga/executor.rb (+24 -11) =================================================================== --- lib/droonga/executor.rb 2013-09-18 16:56:30 +0900 (97dea4a) +++ lib/droonga/executor.rb 2013-09-19 20:25:15 +0900 (bb649b4) @@ -77,6 +77,13 @@ module Droonga def dispatch(tag, time, record, synchronous=nil) message = [tag, time, record] body, type, arguments = parse_message([tag, time, record]) + reply_to = envelope["replyTo"] + if reply_to.is_a? String + envelope["replyTo"] = { + "type" => type + ".result", + "to" => reply_to + } + end post_or_push(message, body, "type" => type, "arguments" => arguments, @@ -98,10 +105,13 @@ module Droonga private def post_or_push(message, body, destination) route = nil - unless destination + unless is_route?(destination) route = envelope["via"].pop destination = route end + unless is_route?(destination) + destination = envelope["replyTo"] + end command = nil receiver = nil arguments = nil @@ -114,8 +124,6 @@ module Droonga receiver = destination["to"] arguments = destination["arguments"] synchronous = destination["synchronous"] - else - receiver = envelope["replyTo"] end if receiver output(receiver, body, command, arguments) @@ -141,8 +149,12 @@ module Droonga add_route(route) if route end + def is_route?(route) + route.is_a?(String) || route.is_a?(Hash) + end + def output(receiver, body, command, arguments) - return nil unless receiver + return nil unless receiver.is_a?(String) && command.is_a?(String) unless receiver =~ /\A(.*):(\d+)\/(.*?)(\?.+)?\z/ raise "format: hostname:port/tag(?params)" end @@ -152,18 +164,19 @@ module Droonga params = $4 output = get_output(host, port, params) return unless output - if command - message = envelope - message["body"] = body - message["type"] = command - message["arguments"] = arguments - else + if command =~ /\.result$/ message = { inReplyTo: envelope["id"], statusCode: 200, - type: (envelope["type"] || "") + ".result", + type: command, body: body } + else + message = envelope.merge( + body: body, + type: command, + arguments: arguments + ) end output.post(tag + ".message", message) end -------------- next part -------------- HTML����������������������������...Download