A ColdFusion event gateway listens for events and passes them to ColdFusion for handling by the application listener CFC or CFCs. It must implement the coldfusion.eventgateway.Gateway interface, and use the ColdFusion GatewayServices class. The following image expands on the basic event handling architecture diagram to show how a ColdFusion event gateway works:

ColdFusion event gateway
ColdFusion event gateway

Receiving messages: The event gateway listener thread receives events from an external event source such as a socket or SMSC server, and calls the GatewayServices addEvent method to send a CFEvent instance to ColdFusion.
Sending messages: The ColdFusion event gateway service calls the outgoingMessage method of the event gateway and passes it a CFEvent instance with the destination and message information. The event gateway forwards the message as appropriate to the external receiver.
The event gateway architecture is not limited to handling messages from external sources, such as SMS devices or IM clients. It can also be used to handle events that are internal to the local system or even the ColdFusion application. Also, a gateway does not have to implement two-way communications. 
The sample directory watcher gateway provided with ColdFusion is an example of an internal, one way, gateway. It has a single thread that periodically checks a local directory and sends a message to a CFC when the directory contents change. This gateway does not support outgoing messages. (The code for this gateway is in the gateway/src/examples/watcher directory.) 
Another internal gateway, the asynchronous CFML gateway, is provided as part of the ColdFusion product. Unlike most gateways, it does not have a listener thread. Its outgoingMessage method gets messages from CFML SendGatewayMessage functions, and dispatches them to a CFC onIncomingMessage method for handling. This gateway lets ColdFusion support request-free asynchronous processing. For more information on using this gateway, see Using the CFML event gateway for asynchronous CFCs.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy