Accessing events through a Message Driven Bean (MDB)

The easiest way to consume the BPM-related events is to implement an MDB within an Enterprise Java Bean (EJB) Development Component.

Procedure

  1. Create a new Java class that extends the abstract class com.sap.jms.api.AbstractBPMMessageListener.
  2. Add the following annotation for the created class implementing the MDB:
    @MessageDriven(activationConfig = {
    			@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
    			@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = SELECT_EVENT_PROCESS_STARTED + " OR "
    				+SELECT_EVENT_PROCESS_COMPLETED + " OR "+ SELECT_EVENT_PROCESS_CANCELED + " OR "+ SELECT_EVENT_USERTASK_CREATED + " OR "
    				+SELECT_EVENT_USERTASK_COMPLETED + " OR "+ SELECT_EVENT_USERTASK_CLAIMED + " OR "+ SELECT_EVENT_USERTASK_CANCELED
    				+ " OR "+ SELECT_EVENT_USERTASK_ACTIVATED + " OR "+ SELECT_EVENT_SERVICETASK_STARTED + " OR "
    				+SELECT_EVENT_SERVICETASK_COMPLETED + " OR "+ SELECT_EVENT_INTERMEDIATE_MESSAGE_TRIGGERED + " OR "
    				+SELECT_EVENT_CALLACTIVITY_STARTED + " OR "+ SELECT_EVENT_CALLACTIVITY_COMPLETED) }, mappedName = AbstractBPMMessageListener.JMS_TOPIC_NAME)
  3. Adapt the given selector constants depending on the event types you want to implement. If all event types are to be consumed, no selectors are required.

    The class can then override one, several, or all of the following methods to consume the relevant events:

    @Override
    public final void onBPMEvent(final BPMEventMessage bpmMessage) {
       // process bpmMessage
    }
     
    @Override
    public void onBPMProcessEvent(final BPMProcessEventMessage bpmMessage) {
       // process bpmMessage
    };
     
    @Override
    public void onBPMTaskEvent(final BPMTaskEventMessage bpmMessage) {
       // process bpmMessage
    };

    The BPMEventMessage object is intended to indicate the occurrence of the relevant event in the BPM execution. Therefore, it only carries lightweight information such as the type of event, the timestamp, and an identifier for the related entity. If further information such as a process or task instance is required for an entity, other API managers such as com.sap.bpm.pm.api.ProcessInstanceManager or com.sap.bpm.tm.api.TaskInstanceManager can be used to retrieve the full entity object with further details based on the provided ID. For additional use cases, the native JMS message can also be retrieved with the BPMEventMessage getJmsMessage().