Try OpenEdge Now
skip to main content
BP Server Developer's Guide
Messaging workstep : Message subscriber workstep : Subscriber message handler
 

Subscriber message handler

It is optional to provide a Message Handler class for a Subscriber workstep. If a custom Handler class name is mentioned in the Subscriber workstep properties, then the custom Handler class should implement interface com.savvion.sbm.bizlogic.messaging.MessageHandler
The custom handler class has to provide implementation for following methods from interface:
*public void init();
*public void setContext(ProcessContext context);
*public HashMap execute(List bizMessage);
*public void destroy();
*public HashMap getMessagesToDiscard();
When a custom handler class is provided for a Message Subscriber workstep, BP Server engine first delivers the message to the appropriate waiting subscriber workstep by performing filtering and correlation, and it also updates the dataslot values using the message payload properties. Then BP Server engine instantiates an object of the Handler class and invokes Handler class methods.
Sometimes, the message may not be in the expected format or there can be some error in the message structure or data. In such cases, the message must be discarded without completing the workstep. To do this, user can implement getMessagesToDiscard() method in the custom handler class. This method returns a list of messages to be discarded in a HashMap. After invoking other Handler methods, BP Server checks if any messages are to be discarded by calling this method. If the HashMap returned by this method call is non-empty, then BP Server discards those messages and keeps the workstep in a wait state. A code snippet of a Handler class, where all messages having ‘Price’ property value greater than 5000 are discarded, is shown below.
public class MyHandler implements MessageHandler {
    private BizMessage message = null;
    private HashMap messageToDiscard = new HashMap();
    public void init() {
    }
    public void setContext (ProcessContext context) {
        System.out.println("getInputSlots: " + context.getInputSlots());
    }
    public HashMap execute (List bizMessage) {
        for (Object obj : bizMessage) {
        BizMessage message = (BizMessage) obj;
    if (message.getDoubleProperty("Price") > 5000.0) {
            messagesToDiscard.put(message, "Price too high!");
            } else {
                 // process the message
                ...
                 }
         }
        return new HashMap();
    }
    public void destroy() {
    }
    public HashMap getMessagesToDiscard() {
        return messagesToDiscard;
    }
}