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 command dispatches events to external registered event receivers, which means that the events leave the correlator. Active listeners do not receive emitted events.
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.
You cannot emit the following events:
*An event whose type is defined inside a monitor
*An unroutable event type
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.