Yoji Shidara
null+****@clear*****
Mon Feb 3 17:29:05 JST 2014
Yoji Shidara 2014-02-03 17:29:05 +0900 (Mon, 03 Feb 2014) New Revision: 58d6297e2ae26f76c17c029254773e55247775bf https://github.com/droonga/droonga.org/commit/58d6297e2ae26f76c17c029254773e55247775bf Message: Write about request logging in input adapter Modified files: tutorial/plugin-development/input-output/index.md Modified: tutorial/plugin-development/input-output/index.md (+30 -0) =================================================================== --- tutorial/plugin-development/input-output/index.md 2014-02-03 16:37:23 +0900 (f35b7a2) +++ tutorial/plugin-development/input-output/index.md 2014-02-03 17:29:05 +0900 (7e2a45b) @@ -150,6 +150,36 @@ If you have [jq][] installed, you can use `jq` instead of `tr`: jq -c . search-columbus.json | fluent-cat starbucks.message +## Do something in the plugin + +The plugin we have created do nothing so far. Let's get the plugin to do some interesting. + +Firse of all, trap `search` request and log it. Update the plugin like below: + +lib/droonga/plugin/input_adapter/example.rb: + +~~~ +module Droonga + class ExampleInputAdapterPlugin < Droonga::InputAdapterPlugin + repository.register("example", self) + + command "search" => :adapt_request + def adapt_request(input_message) + $log.info "ExampleInputAdapterPlugin", message: input_message + end + end +end +~~~ + +And restart fluentd, then send the request same as the previous. You will see something like below fluentd's log: + +~~~ +2014-02-03 16:56:27 +0900 [info]: ExampleInputAdapterPlugin message=#<Droonga::InputMessage:0x007ff36a38cb28 @raw_message={"body"=>{"queries"=>{"result"=>{"output"=>{"limit"=>-1, "attributes"=>["_key"], "elements"=>["startTime", "elapsedTime", "count", "attributes", "records"]}, "condition"=>{"matchTo"=>"_key", "query"=>"Columbus"}, "source"=>"Store"}}}, "replyTo"=>{"type"=>"search.result", "to"=>"localhost:24224/output"}, "type"=>"search", "dataset"=>"Starbucks", "id"=>"search"}> +2014-02-03 16:56:27 +0900 output.message: {"inReplyTo":"search","statusCode":200,"type":"search.result","body":{"result":{"count":2,"records":[["2 Columbus Ave. - New York NY (W)"],["Columbus @ 67th - New York NY (W)"]]}}} +~~~ + +This shows the message is received by our `ExampleInputAdapterPlugin` and then passed to Droonga. Here we can modify the message before the actual data processing. + [tutorial]: ../../ [overview]: ../../../overview/ -------------- next part -------------- HTML����������������������������... Download