User Guide

Table Of Contents
Using the CFML event gateway for asynchronous CFCs 1039
Using the CFML gateway
The following procedure describes how to use an asynchronous CFC that has a single,
onIncomingMessage method.
To use an asynchronous CFC:
1.
Create a CFC with an onIncomingMessage method. Put the CFC in an appropriate directory
for your application. For example, you can put it in the cf_root\WEB-INF\cfusion\gateway\cfc
directory on J2EE configurations, in the cf_root\gateway\cfc directory on server configurations,
or in a subdirectory of these directories. ColdFusion MX is installed with mappings to these cfc
gateway directories.
The
onIncomingMessage method must take a CFEvent structure that contains input
information in its Data field, and processes the contents of the Data field as needed.
2.
Use the Gateways page in the ColdFusion MX Administrator to add an instance of the CFML
event gateway type. Specify the following:
A unique Gateway ID.
The path to the CFC that you created in step 1.
The startup mode. Select Automatic startup mode to start the event gateway when
ColdFusion MX starts up.
Do not specify a configuration file.
3.
Start the event gateway instance.
4.
Write CFML code that uses SendGatewayMessage functions to send messages in structures to
the event gateway instance ID that you specified in step 2. The
SendGatewayMessage function
returns true if the gateway successfully queues the message in the ColdFusion MX Gateway
Service; false, otherwise. It does not ensure that the CFC receives or processes the message.
5.
Run your CFML application.
Example: logging messages
The following asynchronous CFML event gateway CFC uses the
cflog tag to log a message to a
file in the ColdFusion MX logs directory. The CFC takes a message with the following fields:
file The name of the file in which to put the message. The default value is defaultEventLog.
type The cflog type attribute to use. The default value is info.
message The message text.
<cfcomponent>
<cffunction name="onIncomingMessage" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<cfscript>
if (NOT IsDefined("CFEvent.Data.file")) {
CFEvent.Data.file="defaultEventLog"; }
if (NOT IsDefined("CFEvent.Data.type")) {
CFEvent.Data.type="info"; }
</cfscript>
<cflog text="#CFEvent.Data.message#"
file="#CFEvent.Data.file#"