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.
Note: The emit command is superseded by the send command. See Generating events with the send command. The emit command 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.
You cannot emit the following events:
*An event whose type is defined inside a monitor
*An unroutable event type
If a correlator is configured to connect to UM then a channel might have a corresponding UM channel. If there is a corresponding UM channel then UM is used to emit the event to that UM channel.
See Choosing when to use UM channels and when to use Apama channels.
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.