processi

about processes and engines

openwfe-ruby

openwfe-ruby is a library for interacting with OpenWFE, as its name implies, it’s written in Ruby. Yes, you can leverage OpenWFE from your Ruby application.

I wrote openwfe-ruby as I was spending some time in Costa Rica. I taught myself Ruby by writing a simple drill program for revising my spanish vocabulary and verbs. Then I wrote a first version of openwfe-ruby, based on the openwfe-python and openwfe-dotnet connectors.

Ruby is very elegant, as elegant as, well, I won’t tell.

I just wrote a listen / dispatch pair in Ruby for receiving / sending back workitems directly. An usage example :

require 'ocodec'

sl = OpenWFE::SocketListener.new('127.0.0.1', 7010)
    #
    # listens on port 7010 of the local interface

sl.listen do |workitem|

    workitem.attributes['ruby?'] = 'yes'
    puts "received workitem for flow #{workitem.attributes['__subject__']}"
        #
        # let's perform some modifications on the workitem

    OpenWFE.dispatchWorkitem('127.0.0.1', 7007, workitem)
        #
        # and then, let's send it back to the engine (listening on port 7007)
end

As you can see, this piece of code, once running will listen for incoming OpenWFE workitems on port 7010. You have to set up a participant in etc/engine/participant-map.xml for it :

    <participant name="my-ruby-participant">
        <param>
            <param-name>dispatcherClass</param-name>
            <param-value>openwfe.org.engine.impl.dispatch.SocketDispatcher</param-value>
        </param>
        <param>
            <param-name>host</param-name>
            <param-value>127.0.0.1</param-value>
        </param>
        <param>
            <param-name>port</param-name>
            <param-value>7010</param-value>
        </param>
        <param>
            <param-name>workItemCoder</param-name>
            <param-value>xmlCoder</param-value>
        </param>
    </participant>

It’s important to set the ‘workitemCoder’ to ‘xmlCoder’, other workitem encoding formats are not supported by openwfe-ruby.

Then you can use the new participant from your process definition :

<sequence>
    <participant ref="alice" />
    <participant ref="my-ruby-participant" />
    <participant ref="bob" />
</sequence>

openwfe-ruby is still very young, this listen/dispatch pair, for example, doesn’t handle delivery problems. Some workitem attribute types encoding have not yet been implemented (XmlAttribute, Base64Attribute).
So if someone with Ruby experience and lots of passion is willing to enhance this connector, he (or she) is welcome.

download : openwfe-ruby-1.7.1pre3-src.zip

Written by John Mettraux

June 1, 2006 at 8:41 pm

Posted in dev, openwfe, oss, ruby, workflow

%d bloggers like this: