The messaging system in WSRFlite

Messaging is used for two things

  • communication among service instances: as WSRFlite WS-Resource instances are not usually resident in memory, they can communicate reliably using internal messages
  • reliable and asynchronous communication with external services through a plugin mechanism

    The messaging system offers plugin capability, for example the WS-BaseNotification support is realised as a plugged-in messaging provider.

The internal message system

To send a message asynchronously to a service instance, you can use the following code.

Message m= new Message(...);
//send message to instance with id "instanceid"
Kernel.getMessaging().getQueue(instanceid).publish(m);

The publish() method returns immediately. Messages are stored in a persistent queue.

The target WS-Resource can pick up its message at any time as follows:

//get messages
PullPoint p=Kernel.getMessaging().getPullPoint(getUniqueId());
while(p.hasNext()){
  
  Message m = p.next();
  //process message...

}

There is a hook method postActivate() that is called immediately after the WS-Resource is activated, that is immediately before the actual web method is invoked. This can be overwritten in your service class.

Plugging in your own messaging provider

If you want to plug in your own communication scheme (such as sending messages out using web services), you can write a class implementing IMessagingProvider, and return your own Publisher implementation. Check the WS-BaseNotification code for an example.