Try OpenEdge Now
skip to main content
BP Server Developer's Guide
JMS based event publisher : Event publisher example
 

Event publisher example

This section provides an example to write a client code to subscribe events from the already created Event Channels.
You can refer to the example code for details at OEBPS_HOME\bpserver\examples\EventPublisherExample.zip.
private static void subscribeBP ServerMessages(){
    Session tsession = null;
    try {
    BMJMSService jmsService = new BMJMSService(factory_name, provider);
    //post-filter expression based on SQL92
    String postFilter = "";
    if((appName != null) && (!appName.equals(""))) {
    postFilter = "PROCESSTEMPLATENAME = '" + appName + "'";
    }
    // first parameter is connection factory (if null take default)
    // second and third parameter is userName and password. By default security is not enabled.
    javax.jms.Connection conn = jmsService.createConnection(null, user, password);
    tsession = jmsService.createSession(conn);
    //Example for Post Filter on event:::
    //postFilter = "PROCESSTEMPLATENAME = 'Hiring' AND EVENT_VALUE = 'I_COMPLETED'";
    //Create the subscriber with the above message filter
    javax.jms.MessageConsumer tsubscriber = jmsService.createMessageConsumer(tsession, eventPublisherTopic, postFilter);
    while (true) {
    /* Subscribe the message from the topic in a loop*/
    Message msg = tsubscriber.receive();
    if(msg.propertyExists("PROCESSTEMPLATENAME")) {
    System.out.println();
    System.out.println("Message received");
    System.out.print("ProcessTemplateName=" +
    msg.getStringProperty("PROCESSTEMPLATENAME"));
    
    if(msg.propertyExists("PROCESSINSTANCEID")) {
    System.out.print(" | ProcessInstanceID=" +
    msg.getLongProperty("PROCESSINSTANCEID"));
    }
    if(msg.propertyExists("WORKSTEPNAME")) {
    System.out.print(" | WorkStepName=" +
    msg.getStringProperty("WORKSTEPNAME"));
    System.out.println();
    }
}    } catch (JMSException e) {
    System.out.println("Exception occurred: " + e.toString());
    } finally {
    try {
//close the session properly to avoid memory leak
if (tsession != null) {
    tsession.close();
    }
} catch(JMSException e) {
    System.out.println("Exception occurred while closing Topic Session: "
+ e.toString());
    }
    }
}