Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Defining What Happens When Matching Events Are Found | Generating events | Generating events to emit to outside receivers
 
Generating events to emit to outside receivers
The emit statement dispatches events to external registered event receivers, which means that the events leave the correlator. Active listeners do not receive emitted events.
Note: 
The emit statement is superseded by the send statement. See Generating events with the send statement. The emit statement will be deprecated in a future release. Use send rather than emit.
There are two formats available for using emit. You can directly emit an event, as the example below does first, or else place the event in a string and emit that. If you use this latter format, you must ensure that you define the string to represent a valid event. The correlator does not check whether the string you specify represents an event that is compliant with any event type that has been injected. In fact, you can use this mechanism to emit an event of a type that has not been defined in EPL anywhere else.
For example, consider a revised version of an earlier example. The result, instead of being printed as a message on the screen, is now being sent out as an event message:
event StockTickPriceChange {
   string owner;
   string name;
   float price;
}
 
// A new processTicks action that dispatches an output event
// to external applications instead of logging
action processTicks() {
 
// The following emit format sends the event itself.
   emit StockTickPriceChange(currentStock.owner,
     newTick.name, newTick.price) to
     "com.apamax.pricechanges";
 
// Or, use the following emit format, which sends a string that
// contains the event.
   emit "StockTickPriceChange(\""+currentStock.owner+
     "\",\""+newTick.name+"\", "+newTick.price.toString()+")" to
     "com.apamax.pricechanges";
Events are emitted onto named channels. In the above code the StockTickPriceChange event is being published on the com.apamax.pricechanges channel. For an application to receive events from Apama it must register itself as an event receiver and subscribe to one or more channels. Then if events are emitted to those channels they will be forwarded to it.
Channels effectively allow both point-to-point message delivery as well as through publish-subscribe. As in the above example, channels can be set up to represent topics. External applications can then subscribe to event messages of the relevant topics. Otherwise a channel can be set up purely to indicate a destination and have only one application connected to it.
The emit statement can operate on any values as well as events, provided that the any value is of a routable event type.
You cannot emit the following events:
*An event whose type is defined inside a monitor.
*An unroutable event type. There is a runtime check if the event (or one of its members) can contain an any field; an exception is thrown if the any field contains an object of type action, chunk, listener, or stream.
If a correlator is configured to connect to Universal Messaging, then a channel might have a corresponding Universal Messaging channel. If there is a corresponding Universal Messaging channel, then Universal Messaging is used to emit the event to that Universal Messaging channel.
See Choosing when to use Universal Messaging channels and when to use Apama channels.