Flex Configuration Demystified: services-config.xml, Destinations, and Channels

For a long time, my IM status really was "LCDS configuration sucks," and I meant it. I found its XML files very intimidating, and I deal with XML-based frameworks on a daily basis! Over the past week, I've come to realize it's not that bad. More than anything else, it was the documentation that got me a bit backwards. I don't know if it has to do with its style or my method of comprehension. It seems to immediately dive in to minute configuration detail without ever giving a high-level overview of what all the stuff it talks about actually is.

So here's the deal:

When you want Flex to talk to ColdFusion, LCDS, or Blaze, there's really only three things you need to know how to set up.

Channels

A "channel's" just which network connection to use to talk to the server. Simply put, it's the URL of the servlet you'd like to talk to, such as "/flex2gateway" for ColdFusion Flash Remoting or "/messagebroker/amf" for Blaze along with the type of channel, such as AMFChannel (wants to use AMF, a binary serialization of ActionScript objects) or HTTPChannel (wants to use AMFX, which is an XML serialization of ActionScript objects).

Destinations

A "destination" is a server-side Java class that you'll talk to with a RemoteObject, Consumer, or Producer. A destination typically has a "source" configured, which is the name of the class to which to speak. It's bit funky for ColdFusion, though, in that the source is typically stated in MXML (if you look at ColdFusion's services-config.xml, you'll see that the source is "*").

Adapters

Adapters provide bridges between the messaging infrastructure and server-side code. For the most part, I've used to built-in adapters, but I have built custom Java adapters for the purposes of intercepting and manipulating realtime messages before they're sent out to their channels. A great example is the CFEventGatewayAdapter, which allows incoming Flex realtime messages to interact with ColdFusion Event Gateways.

So why the ugly XML?

The XML files that blow minds (services-config.xml, remoting-config.xml, etc.) aren't actually necessary. They're handy, in that they provide a topic-specific syntax for describing available services to Flex applications, but there's nothing preventing you from using server-side bootstrappers and client-side ActionScript code to configure it all. The code would just become a mess in a big hurry!

Here's a handy, birds-eye view of these files, leaving a few files and a bunch of subtopics (security) out and focusing on the core:

  1. services-config.xml

    This file's the master: if you look inside, it actually includes the others, such as remoting-config.xml. It'll typically define default channels for destinations to use, logging, session semantics such as timeout, and other aspects of Flex remoting / messaging that apply to all services.

  2. remoting-config.xml
  3. This one just an include> that provides a place to configure remoting (RPC-style, RemoteObject) destinations. It may define adapters specific to these destinations.

  4. messaging-config.xml
  5. Like remoting-config.xml, this is just another include that provides a place for configuring messaging (realtime) destinations. It may define adapters specific to these destinations.

Conclusion Hope this helps clarify a bit of what all those terms are, and why all of those XML files exist! I've found the BlazeDS documentation to be of the most help for further information, although it's a terribly dry read.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Joe,

Thanks for this, it really helps to put some things into perspective. One thing that we've been struggling with, in anticipating working with Flex, is how we manage the configuration to speak with a specific CF instance when running a multi-instance config. I'm guessing that this would help to resolve this, though it's still a little unclear...
# Posted By Steve 'Cutter' Blades | 1/25/08 10:51 AM
Hey Cutter,

For the bits that go over http (RemoteObject, polling AMF channels), when a Flex app makes a request back to your server, it's just an HTTP request made through your browser to the endpoint URL specified. In this regard, it's like any other request, be it whole-page, ajax, etc.

If you've got a load balancer or something in place that determines a CF server to which the request would be made, sticky session rules would still apply.

Is that at all what you're getting towards?
# Posted By Joe Rinehart | 1/25/08 11:03 AM
Hey Joe,

That's close, but not exactly. When setting up a Flex Project, it asks for things like the webroot, etc., that allows for testing from within the IDE (with live data). But, we run the multi-instance JRun edition on our desktops, breaking apart are base app from our admin app, and run multi-instance at the servers as well (one running, the other as backup). Pathing appears to be different, in this case, but we haven't found any documentation on this, as everything speaks to developing on top of the standalone server (which won't work for us)....
# Posted By Steve 'Cutter' Blades | 1/25/08 3:39 PM
nice post Joe! A suggested great follow up is how to setup for HTTPS use and a even nicer one would include how to get mixed HTTP and HTTPS on same server instance. Docs are really slim on all this.

peas

DK
# Posted By Douglas Knudsen | 1/25/08 10:19 PM
@Cutter,

Gotcha. I run two instance of CF (one JRun, and another under JBoss) as well as Java apps (JBoss), and have Flex projects talking to them all.

For all of them, the services-config.xml's definitions of the channels use tokens for the server's URL and port ({server.nnn} in the XMl).

When I create a ColdFusion Flex project, I do _not_ use the Wizard to configure my project for the CF server to use. Instead, I create a Flex project w/o a backend technology, then add the appropriate compiler arguments via its properties dialogue (e.g. "-services=/path/to/instances/services-config.xml -context-root=/").

For deployment, I'm looking for a clean way to runtime configure this stuff, but for now I use Ant to create environment-specific builds of my apps (much in the same way I do with ColdFusion).
# Posted By Joe Rinehart | 1/28/08 9:16 AM
@Cutter, when using multiserver instances you just need to point it to your cfusion war folder for the webroot because in fact Flex Builder is looking for a WEB-INF/flex folder inside of the provided path.

The only big issue when using multiserver instances is to be sure that rtmp channels are using unique listening ports.

@Joe
You can also skip configure destinations at runtime for server-side configuration by using the Java API

http://www.onflexwithcf.org/index.cfm/2007/7/3/Usi...
# Posted By João Fernandes | 1/30/08 4:34 AM
© 2008 Firemoss, LLC
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.