Just another brainstorm; I thought we should split this thread into
two; one for POJOs & mapping to JBI/JSR 181/AnDI and another to doing
conversations/orchestration/workflow.

So we've got BeanFlow for writing POJO based workflows; I was
wondering about how we could link that to JBI POJOS (supporting JBI /
JSR 181 / AnDI annotations etc).

Here's a quick brainstorm. The basic idea is to introduce a little
POJO wrapper for an asynchronous JBI message exchange (a
request-response or one way which could take time to complete etc).
This POJO would implement the Activity interface from BeanFlow so we
could easily use it in a full workflow if desired. Then this POJO
would also be tied to a specific Destination. Also this POJO would be
injected by the container.

Many workflows only require making a single request on a number of
different endpoints - e.g. the following example talks to A, then
after thats complete, talks to B and C in parallel then when both of
those complete we talk to D. If we need to keep re-requesting services
we could reset the ExchangeActivity maybe (or just go back to using
the Destination directly).

So here's a little example...

public class MyWorkflow {

 @Endpoint("service:foo") ExchangeActivity a;
 @Endpoint("jms://activemq/foo.bar") ExchangeActivity b;
 @Endpoint("service:bar") ExchangeActivity c;
 @Endpoint("service:xyz") ExchangeActivity d;

  @PostConstruct
  public void start() {
    NormalizedMessage message = a.createInMessage();
    message.setContent(new StringSource("<hello>world!</hello>"));
    ...
    a.request(message);
 }

 @Join
  public void onJoin(Activity exchange) {
     if (exchange == a) {
       // lets fire off to be and c
       b.request(createRequestB());
       c.request(createRequestC());
    }
    else if (b.isComplete() && c.isComplete()) {
      d.request(createRequestD());
   }
}


So requests are all asynchronous and we get a join callback when any
of the exchanges (or other arbirary activities) change
(complete/fail/timeout) so we can perform whatever join conditions we
need.

I did ponder about using annotations to create methods for
'aComplete()' and 'bAndCComplete()' but it seems easier to use Java
code for boolean logic. The downside of this though is its not easily
possible to create tooling visualisations of this workflow.

We could use some kind of join language though so we could rewrite the
join logic as

@Join("a")
public void completedA() {
       b.request(createRequestB());
       c.request(createRequestC());
}

@Join("b and c")
public void completedBandC() {
      d.request(createRequestD());
}

where the  of a, b, c would resolve to properties or fields which must
return instances of type Activity from BeanFlow.

The nice thing about this use of @Join is that it would work with any
BeanFlow construct, JBI or otherwise. Then we are only really
introducing a POJO ExchangeActivity and an annotation to inject it
based on a destination URI (@Endpoint).

Am not particularly wedded to the names of ExchangeActivity and
@Endpoint but it was the best I could come up with without having too
much coffee yet. We might want to split @Endpoint into a couple of
tags as we might want to include both the endpoint URI and the type of
the request, InOut/InOnly etc.

Thoughts?
--

James
-------
http://radio.weblogs.com/0112098/

Reply via email to