ColdFusion event gateways presentation at Spring
Adobe’s John Cummings gave an introduction to event gateways functionality available in ColdFusion MX 7 Enterprise. Cummings is the manager of Gold ColdFusion/JRun support at Adobe. I learned quite a bit about event gateways and how they could bring quite a bit of benefit to my web applications.
As a quick introduction, event gateways are a way to have the ColdFusion runtime process data that doesn’t necessarily have to be requested via HTTP.
Technorati Tags:
coldfusion
Types of gateways
The two types of gateways are initiator gateways, which initiate processes, and responder gateways, which run processes in response to an event. This frees ColdFusion’s functionality from the confines of a browser; now ColdFusion can respond to events initiated by SMS, different sockets, XMPP instant messaging, and more. Initiator gateways generate event messages using CFML code and use the SendGatewayMessage() function to send the messages to the appropriately configured gateway instances. Responder gateways receive messages from gateway instances; this fires CFML code that do any number of data processing tasks based on the messages received.
These gateway types are written in Java, so CFMX7 ships with the Gateway API so developers can write their own. The Java code has access to the coldfusion.gateway.CFEvent class. Data passed to the gateway is defined in parameters named GatewayID, Data, OriginatorId, GatewayType, CfcPath, CfcMethod, and CfcTimeout.
Separate resource pool
Another large benefit is the ability for already existent HTTP apps to off-load tasks to the event gateways pool asynchronously. This way the user doesn’t need to wait for tasks like Verity indexing to complete before the rest of his or her page is processed. Plus this frees up resources from the normal ColdFusion request pool and off-loads them to another request pool. Only the developer is to blame if large ColdFusion processes slow other ones down if they have CFMX 7 Enterprise on-hand.
Out of the box gateways
ColdFusion MX 7 Enterprise comes with a wide array of pre-built gateway types. There is already a gateway type written to handle the asynchronous CFML processing I mentioned above. This would be awesome for actions that trigger Verity actions like indexing new content and deleting old content, and it would be awesome for intensive database queries that do not get run as a result of any interface action.
The DirectoryWatcher gateway allows you to write a script that responds to changes in any given set of the server’s file system. I thought this would be an awesome way to tap actions caused by clients other than Contribute 3 into the Web Publishing System framework. Imagine the WPS being able to react to file changes caused by Dreamweaver, Eclipse, FTP, etc.
Other out-of-the-box gateways include
- a JMS gateway that can consume or produce JMS messages
- a socket gateway that watches particular server sockets
- an XMPP gateay that allows ColdFusion applications to interact with IM clients like Google Talk, AIM, Yahoo! Messenger, and MSN Messenger
Role of the ColdFusion Administrator
You manage gateway types and instances of these gateway types in the ColdFusion administrator. Makes sense.