ColdFusion 9.0 Resources |
About event gatewaysColdFusion event gateways are ColdFusion elements that let ColdFusion react to or generate external events or messages in an asynchronous manner. Event gateways let a ColdFusion application handle information that does not come through an HTTP request. For example, you can use event gateways to handle instant messages, short messages from mobile devices, or messages sent to a TCP/IP port. The event gateway mechanism has the following major features:
ColdFusion includes several product-level event gateways, such as a gateway for the XMPP (Extensible Messaging and Presence Protocol) instant messaging protocol. Adobe also provides the source for several example gateways, such as a generalized socket gateway, that you can extend to handle your specific needs. You can also write your own gateways in Java to handle other event or messaging technologies supported by the Java runtime or by third-party providers, such as gateways for additional instant messaging protocols, gateways for specific ERP systems, or other protocols, such as NNTP. Using event gatewaysBecause event gateways provide a generalized asynchronous messaging mechanism, you can use them with many kinds of event or messaging resources. For example, ColdFusion includes gateways (either product quality, or lighter weight example gateways) for communicating between ColdFusion applications and the following types of resources:
Event gateways are not limited to sending or receiving information using communications protocols. For example, ColdFusion includes an example event gateway that monitors changes to a directory and invokes a CFC method whenever the directory changes. ColdFusion also includes an event gateway that lets a CFML application “call” a CFC asynchronously and continue processing without getting a response from the CFC. Just as you can create event gateways that serve many different event or messaging based technologies, you can write many kinds of applications that use them. Just a few examples of possible gateway uses include the following. Server to client push examples
Client to server examples
Event gateway terms and conceptsThis document uses the following terms when referring to event gateways:
How event gateway applications workThe following diagram shows the architecture of ColdFusion event gateway applications: How event gateways interactTypically, a ColdFusion event gateway instance, a Java object, listens for events coming from an external provider. For example, a general socket event gateway listens for messages on an IP socket, and an SMS event gateway receives messages from an SMSC server. Each event gateway instance communicates with one or more listener CFCs through the ColdFusion event gateway service. The listener CFCs receive CFEvent object instances that contain the messages, process them, and can send responses back to the event gateway, which can send the messages to the external resources. Alternatively, a ColdFusion application can initiate a message by calling a ColdFusion function that sends the message to the event gateway. The event gateway then forwards the message to an external resource, such as an instant messaging server. A CFC in the application listens for any responses to the sent message. Some event gateways can be one way: they listen for a specific event and send it to a CFC, or they get messages from a ColdFusion function and dispatch it, but they do not do both. The example DirectoryWatcherGateway discussed in Example event gateways listens for events only, and the asynchronous CFML event gateway receives messages from CFML only. (You could even say that the directory watcher gateway doesn’t listen for events; it creates its own events internally by periodically checking the directory state.) For information on the asynchronous CFML event gateway, see Using the CFML event gateway for asynchronous CFCs. Event gateway structureJava programmers develop ColdFusion event gateways by writing Java classes that implement the coldfusion.eventgateway.Gateway interface. ColdFusion event gateways normally consist of one or more threads that listen for events from an event provider, such as a Socket, an SMSC server, or some other source. The event gateway sends event messages to the ColdFusion event gateway service message queue, and provides a method that gets called when an event gateway application CFC or CFM page sends an outgoing message. The event gateway class can also do the following:
About developing event gateway applicationsColdFusion application developers write applications that use event gateways. The person or company that provides the event gateway supplies gateway-specific information to the ColdFusion developer. This information must include the structure and contents of the messages that the ColdFusion application receives and sends to the event gateway, plus any information about configuration files or helper methods that the ColdFusion application could use. The ColdFusion developer writes a CFC that listens for messages. Many event gateway types send messages to a listener CFC method named onIncomingMessage. A minimal event gateway application could implement only this single method. More complex event gateway types can require multiple CFC listener methods. For example, the ColdFusion XMPP IM event gateway sends user messages to the onIncomingMessage CFC method, but sends requests to add buddies to the onAddBuddyRequest CFC method. Depending on the event gateway and application types, the event gateway application could include CFM pages or CFC methods to initiate outgoing messages. The application also could use an event gateway-specific GatewayHelper object to do tasks such as getting buddy lists in IM applications or getting the status of a messaging server. The ColdFusion application developer also configures an event gateway instance in the ColdFusion Administrator, and possibly in a configuration file. The ColdFusion Administrator configuration information specifies the listener CFC that handles the messages from the event gateway and other standard event gateway configuration details. The configuration file, if necessary, contains event gateway type-specific configuration information. |