User Guide

Table Of Contents
Developing an event gateway application 1031
The listener method does the following:
1.
Takes a single parameter, a CFEvent structure, described in the following section.
2.
Processes the contents of the instance as required by the application.
3.
Optionally, returns an outgoing message to the event gateway in a cfreturn tag. It can also
send a message back to the event gateway by calling the ColdFusion
SendGatewayMessage
function.
The following code shows a listener CFC with an
onIncomingMessage method that echoes a
message back to the Socket event gateway that sent it. It contains the minimum code required to
process an incoming message and respond to the sender using the socket gateway.
<cfcomponent displayname="echo" hint="echo messages from the event gateway">
<cffunction name="onIncomingMessage" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<!--- Create a return structure that contains the message. --->
<cfset retValue = structNew()>
<cfset retValue.DestinationID = arguments.CFEvent.OriginatorID>
<cfset retValue.MESSAGE = "Echo: " & arguments.CFEvent.Data.MESSAGE>
<!--- Send the return message back. --->
<cfreturn retValue>
</cffunction>
</cfcomponent>
Other event gateways require different fields in the return structure. For example, to echo a
message using the SMS event gateway, you use the following lines to specify the return value:
<cfset retValue.command = "submit">
<cfset retValue.sourceAddress = arguments.CFEVENT.gatewayid>
<cfset retValue.destAddress = arguments.CFEVENT.originatorid>
<cfset retValue.ShortMessage = "Echo: " & arguments.CFEvent.Data.MESSAGE>
The CFEvent structure
The ColdFusion event gateway service passes a CFEvent structure with information about the
message event to the listener method. The following table describes the structure’s fields:
Field Description
GatewayID The event gateway that sent the event; the value is the ID of an event gateway
instance configured on the ColdFusion MX Administrator Gateways page. If the
application calls the
SendGatewayMessage function to respond to the event
gateway, it uses this ID as the function’s first parameter.
Data A structure containing the event data, including the message. The
Data
structure contents depend on the event gateway type.
OriginatorID The originator of the message. The value depends on the protocol or event
gateway type. Many event gateways require this value in response messages to
identify the destination of the response. Identifies the sender of the message.