Accessing events through a JMS API
Using an MDB is not always an option, as in some cases more control is required for processing the events. JMS provides a way to consume topics by looking up the TopicConnectionFactory and the topic from the Java Naming and Directory Interface (JNDI) by their names.
For details on how to use JMS APIs, see the JMS Overview section.
The BPM API provides string constants of the lookup name to retrieve the TopicConnectionFactory and the topic by JNDI lookups:
-
Retrieve an instance of javax.jms.TopicConnectionFactory related to the BPM event topic using the constant com.sap.bpm.jms.api.BPMJmsManager.JMS_TOPIC_CONNECTION_FACTORY_NAME.
-
Retrieve an instance of javax.jms.Topic related to the BPM event topic using the constant com.sap.bpm.jms.api.BPMJmsManager.JMS_TOPIC_NAME.
The BPM API also provides a more comfortable alternative for retrieving the resolved instances for both TopicConnectionFactory and topic from JNDI:
-
Returns an instance of javax.jms.TopicConnectionFactory: BPMJmsManager.getBPMJmsConnectionFactory().
-
Returns an instance of javax.jms.Topic: com.sap.bpm.jms.api.BPMJmsManager.getBPMJmsTopic().
To get an instance of the BPMJmsManager, call com.sap.bpm.api.BPMFactory.getBPMJmsManager().
When receiving a javax.jms.Message, you require particular knowledge about the content of the JMS message. In order to access this content safely, the BPM API provides a semantic object BPMEventMessage, which is returned by com.sap.bpm.jms.api.BPMJmsManager.mapJmsMessageToBPMEventMessage(Message). It is the same Java type as provided through the MDB method. Depending on the event type provided by com.sap.bpm.jms.api.BPMEventMessage.getBPMEventType(), isProcessEventType() or isTaskEventType(), it is valid to cast the BPMEventMessage to BPMProcessEventMessage or BPMTaskEventMessage, respectively.
To subscribe to the topic, execute the developed code with a user who has the following UME action: SAP_BPM_JMS_BPMEventTopic_Subscribe. For more information, see Authorizations and Roles.