Handling incoming messages

When a Flex application sends a message to a ColdFusion application, the Data Services Messaging event gateway sends a CFEvent structure to the onIncomingMessage function of the configured CFC, with the following information mapped to the data of the event:

Name

Contents

body

Body of the message.

ClientID

ID of the client that sent the message.

CorrelationID

Correlation identifier of the message.

Destination

Flex destination of the message.

Headers

If the message contains any headers, the CFML structure that contains the header names as keys and values.

Timestamp

Timestamp of the message.

The incoming message data structure also includes the values of messageID and timeToLive from the Flex message.

Incoming message handling example

The following example places data that is contained in the body of the message from the Flex application into a structure. It then uses the contents of the structure to generate an e-mail message.

<cfcomponent displayname="SendEmail" hint="Handles incoming message from Flex"> 
    <cffunction name="onIncomingMessage" returntype="any"> 
    <cfargument name="event" type="struct" required="true"> 
 
        <!--- Create a structure to hold the message object sent from Flex---> 
        <cfset messagebody = event.data.body> 
 
        <!--- Populate the structure. ---> 
        <cfset mailfrom="#messagebody.emailfrom#"> 
        <cfset mailto="#messagebody.emailto#"> 
        <cfset mailsubject="#messagebody.emailsubject#"> 
        <cfset mailmessage ="#messagebody.emailmessage#"> 
 
        <!--- Send e-mail with values from the structure. ---> 
        <cfmail from="#mailfrom#" 
            to="#mailto#" 
            subject="#mailsubject#"> 
            <cfoutput>#mailmessage#</cfoutput> 
        </cfmail> 
    </cffunction> 
</cfcomponent>

If the Flex application sends the message in the header instead of in the body, you create and populate the structure, as the following example shows:

<cfset messageheader = StructNew()> 
<cfset messageheader.sendto = event.data.headers.emailto> 
<cfset messageheader.sentfrom = event.data.headers.emailfrom>                     
<cfset messageheader.subject = event.data.headers.emailsubject> 
<cfset messageheader.mailmsg = event.data.headers.emailmessage> 
 
<cfset mailfrom="#messageheader.sentfrom#"> 
<cfset mailto="#messageheader.sendto#"> 
<cfset mailsubject="#messageheader.subject#"> 
<cfset mailmessage ="#messageheader.mailmsg#">