User Guide

Table Of Contents
1098 Chapter 45: Creating Custom Event Gateways
String path = listeners[i];
CFEvent event = new CFEvent(gatewayID);
Hashtable mydata = new Hashtable();
mydata.put("MESSAGE", theInput);
event.setData(mydata);
event.setGatewayType("SocketGateway");
event.setOriginatorID(theKey);
event.setCfcMethod(cfcEntryPoint);
event.setCfcTimeOut(10);
if (path != null)
event.setCfcPath(path);
boolean sent = gatewayService.addEvent(event);
if (!sent)
log.error("SocketGateway(" + gatewayID + ") Unable to put message on
vent queue. Message not sent from " + gatewayID + ", thread " + theKey
+ ". Message was " + theInput);
}
}
Responding to a ColdFusion function or listener CFC
The ColdFusion event gateway services call the event gateways
outgoingMessage method to
handle messages generated when an event gateway application listener CFC’s listener method
returns a message or any CFML code calls a
SendGatewayMessage function. This method must
send the message to the appropriate external resource.
The
outgoingMessage method’s parameter is a CFEvent instance, containing the information
about the message to send out. The CFEvent
getData method returns a Map object that
contains event gateway-specific information about the message, including any message text.
All CFEvent instances received by the
outgoingMessage contain information in the Data and
GatewayID fields.
CFEvent instances returned from listener CFC
onIncomingMessage methods include the
incoming message’s originator ID and other information. However, a gateway that might handle
messages from the ColdFusion
SendGatewayMessage function cannot rely on this information
being available, so it is good practice to require that all outgoing messages include the destination
ID in the data Map.
The
outgoingMessage method returns a String value. The CFML sendGatewayMessage
function returns this value to the ColdFusion application. The returned string should indicate the
status of the message. By convention, ColdFusion event gateway
outgoingMessage methods
return “OK” if they do not encounter errors and do not have additional information (such as a
message ID) to return.
Because event messages are asynchronous, a positive return normally does not indicate that the
message was successful delivered, only that the
outgoingMessage method successfully handled
the message. In some cases, however, it is possible to make the
outgoingMessage method at least
partially synchronous. The SMS gateway, for example, provides two
outgoingMessage modes:
Asynchronous mode The outgoingMessage method returns when the message is queued
internally for delivery to the messaging providers short message service center (SMSC)