processi

about processes and engines

amqp, ruote, pong

Hartog de Mik just wrote an investigation into ruote and AMQP. In this blog post, he makes the long jump from zero to ruote + RabbitMQ participants via the vaguely charted ruote-amqp territory.

But right before clicking away to Hartog’s blog post, please consider this pure ruote pong solution :

require 'rubygems'
require 'ruote'

pdef = Ruote.process_definition do
  repeat do
    ping # mister ping, please shoot first
    pong
  end
end

class Opponent
  include Ruote::LocalParticipant

  def initialize (options)
    @options = options
  end

  def consume (workitem)
    puts @options['sound']
    reply_to_engine(workitem)
  end
end

engine = Ruote::Engine.new(Ruote::Worker.new(Ruote::HashStorage.new))

engine.register_participant :ping, Opponent, 'sound' => 'ping'
engine.register_participant :pong, Opponent, 'sound' => 'pong'

wfid = engine.launch(pdef)

sleep 5 # five seconds of ping pong fun

engine.cancel_process(wfid) # game over

 

http://ruote.rubyforge.org (home)
http://groups.google.com/group/openwferu-users (mailing list)
IRC #ruote on freenode.net

 

Written by John Mettraux

September 27, 2010 at 2:24 pm

Posted in ruby, ruote, workflow