Apama 10.7.2 | Connecting Apama Applications to External Components | Correlator-Integrated Support for the Java Message Service (JMS) | Using the Java Message Service (JMS) | Getting started with simple correlator-integrated messaging for JMS | Using EPL to send and receive JMS messages
 
Using EPL to send and receive JMS messages
The EPL code necessary for using correlator-integrated messaging for JMS is minimal.
*Initialization - Your application needs to notify the correlator that the application has been injected and is ready to process events from the JMS broker.
1. Apama recommends that after all an application's EPL has been injected, the application should send an application-defined "start" event using a .evt file. Using an event is clearer and more reliable than enabling JMS message receiving using monitor onload() actions because it is easier to guarantee that all EPL has definitely been injected and is in a good state before the event is sent and JMS message receiving commences.
Software AG Designer, engine_deploy and other tools all ensure that .evt files are sent in after all EPL has been injected.
2. The monitor that handles the application-defined start event (from step 1) should use this JMS event object to notify correlator-integrated messaging for JMS that the application is initialized and ready to receive messages, for example:
on com.mycompany.myapp.Start() {
com.apama.correlator.jms.JMS.onApplicationInitialized();
// Any other post-injection startup logic goes here too.
}
Note:
For simple applications, you can add the EPL bundle Automatic onApplicationInitialized to your project (see also Adding bundles to projects). This bundle will ensure that onApplicationInitialized is called as soon as the entire application has been injected into the correlator. However, in cases where you need to wait for a MemoryStore, database or another resource to be prepared before your application is able to begin to process incoming messages, you should not use the bundle. In these cases, you should write your own start event and application logic.
*Receiving events - After configuring a JMS receiver, add EPL listeners for the events specified in the mapping configuration.
*Sending events - Send the Apama event associated with the JMS message in the Sender Mapping Configuration by using the following syntax:
send event_name to "jms:senderId";
Note that senderId is typically "connectionId-default-sender" unless explicitly configured with a different name. For example, to send an event to the default sender on a connection called MyConnection, use the following:
send MyEvent to "jms:MyConnection-default-sender";
For more information on specifying the message's JMS destination, see Configuring sender event mappings.