Configuring a Message Destination


To begin working with messaging in a Flex application, you need to configure FDS to recognize the incoming messages. This configuration will be done in the messaging-config.xml file.

Here, you can see a sample messaging-config.xml file:

<?xml version="1.0" encoding="UTF-8"?> <service         messageTypes="flex.messaging.messages.AsyncMessage">    <adapters>       <adapter-definition                      default="true"/>       <adapter-definition           />       <adapter-definition           />    </adapters>    <destination >      <adapter ref="cfgateway"/>      <properties>         <gatewayid>*</gatewayid>      </properties>      <channels>         <channel ref="my-rtmp"/>         <channel ref="my-polling-amf"/>      </channels>   </destination> </service> 


Notice that the file has two main sections. First, adapters are defined that list the various types of system FDS to which Flex can send and receive messages. The three default adapters are listed here. If any custom adapters are written for the project, they also would be referenced in the adapters section.

Next, a destination is defined. The destination has an id, which is the name you will use in the MXML tags. (You'll see this in use in the next section.) This is followed by a reference to the proper adapter for the destination. In this example, the message is coming from a ColdFusion event gateway, so the cfgateway adapter is used. Any specific properties, which need to be set, are then added in the properties node. This example uses the gatewayid property of *, which enables the message to define a specific gateway, as opposed to restricting it to a specific event gateway from the server. Finally, the channels that this destination can use are specified. They reference channel-definition nodes in the services-config.xml file.

1.

Open messaging-config.xml from your FDS server (the default directory is driveroot:/fds2/jrun4/servers/default/flex/WEB-INF/flex on Windows). Make a copy of the file before you start because the FDS server does not start if there are errors in this file. Add an adapter definition with an id of cfgateway and a class of coldfusion.flex.CFEventGatewayAdapter.

<adapter-definition     /> 


With this addition, the completed file should read as follows:

<?xml version="1.0" encoding="UTF-8"?> <service         messageTypes="flex.messaging.messages.AsyncMessage">    <adapters>    <adapter-definition               default="true" />    <adapter-definition        />    <adapter-definition        />    </adapters> </service> 


2.

Open typeSalesGateway.xml from the Lesson20/assets folder and copy all the text to the clipboard. Paste this code just after the closing adapter's node of the messaging-config.xml file:

<?xml version="1.0" encoding="UTF-8"?> <service         messageTypes="flex.messaging.messages.AsyncMessage">    <adapters>       <adapter-definition               default="true"/>       <adapter-definition        />       <adapter-definition        />    </adapters>    <destination >       <adapter ref="cfgateway"/>       <properties>          <gatewayid>*</gatewayid>       </properties>       <channels>          <channel ref="my-rtmp"/>          <channel ref="my-polling-amf"/>       </channels>    </destination> </service> 


Note

The code you copied in has several comments, which have been omitted here.

This defines a destination to enable the ColdFusion server to notify your Flex application of changes to sales.

3.

Save and close messaging-config.xml.

4.

Restart the Flex server and verify that there are no errors.




Adobe Flex 2.Training from the Source
Adobe Flex 2: Training from the Source
ISBN: 032142316X
EAN: 2147483647
Year: 2006
Pages: 225

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net