diff --git a/README b/README index 8846b08..daf6a67 100644 --- a/README +++ b/README @@ -208,7 +208,7 @@ Now open a new shell and run the same command again. You should see something like the follow as the output of each: "advertise_services" - ["/simple/hello"] + ["/simple/echo"] Now we need to run a mapper. Mappers can be run from within your Merb or Rails app, from an interactive irb shell, or from the command line. For this example we'll run it from the @@ -237,7 +237,7 @@ This assumes that you have the agents running as indicated in the example above. $ cd nanite $ ./bin/nanite-mapper -i -u mapper -p testing -v /nanite ->> Nanite.request('/simple/hello') {|res| p res } +>> Nanite.request('/simple/echo') {|res| p res } By default this will dispatch to the agent with the lowest reported load average. diff --git a/examples/cli.rb b/examples/cli.rb index 82a194f..8ab8aef 100755 --- a/examples/cli.rb +++ b/examples/cli.rb @@ -4,13 +4,36 @@ require 'nanite' require 'nanite/mapper' +# cli.rb +# +# You will need to have run the bin/rabbitconf script at least one time before you +# run this so the expected users and vhosts are in place in RabbitMQ. +# +# You should also have started the 'simpleagent' nanite in a separate shell by running: +# +# cd /examples/simpleagent +# nanite +# +# This test script takes a little more than 16 seconds to run since we start a new +# mapper within, and pause while we wait for it to initialize, receive pings from +# available agents (which have a default ping time of 15 seconds), and register +# those agents and their methods. When this process is presumed complete after +# 16 seconds we can finally send the nanite agent the task to execute. + Nanite.identity = Nanite.gensym EM.run { AMQP.start(:host => 'localhost', :user => 'mapper', :pass => 'testing', :vhost => '/nanite') + + # start up a new mapper with a ping time of 15 seconds Nanite.mapper = Nanite::Mapper.new(15) + + # have this run after 16 seconds so we can be pretty sure that the mapper + # has already received pings from running nanites and registered them. EM.add_timer(16) do - Nanite.request("/simple/hello", '') do |res| + + # call our /simple/echo nanite, and pass it a string to echo back + Nanite.request("/simple/echo", "hello world!") do |res| p res EM.stop_event_loop end diff --git a/examples/simpleagent/actors/simple.rb b/examples/simpleagent/actors/simple.rb index 1538ac2..a1e134f 100644 --- a/examples/simpleagent/actors/simple.rb +++ b/examples/simpleagent/actors/simple.rb @@ -1,9 +1,11 @@ +# you can execute this nanite from the cli.rb command line example app + class Simple < Nanite::Actor - expose :hello + expose :echo - def hello(payload) - "hello nanite" + def echo(payload) + "Nanite said #{payload.empty? ? "nothing at all" : payload} @ #{Time.now.to_s}" end end