BlazeDS Developer Guide

Accessing dynamic components with a Flex client application

View comments | RSS feed

Using a dynamic destination with a client-side data services component, such as an HTTPService, RemoteObject, WebService, Producer, or Consumer component, is essentially the same as using a destination configured in the services-config.xml file.

It is a best practice to specify a ChannelSet and channel when you use a dynamic destination, and this is required when there are not application-level default channels defined in the services-config.xml file. If you do not specify a ChannelSet and Channel when you use a dynamic destination, BlazeDS attempts to use the default application-level channel assigned in the default-channels element in the services-config.xml file. The following example shows a default channel configuration:

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
    <services>
        ...
        <default-channels>
            <channel ref="my-polling-amf" />
        </default-channels>
        ...
    </services>
    ...
</services-config>

You have the following options for adding channels to a ChannelSet:

  • Create channels on the client, as the following example shows:
    ...
    var cs:ChannelSet = new ChannelSet(); 
    var pollingAMF:AMFChannel = new AMFChannel("my-amf",
        "http://servername:8400/messagebroker/amfpolling");
    cs.addChannel(pollingAMF);
    ...
    
    
  • If you have compiled your application with the server-config.xml file, use the ServerConfig.getChannel() method to retrieve the channel definition, as the following example shows:
    var cs:ChannelSet = new ChannelSet(); 
    var pollingAMF:AMFChannel = ServerConfig.getChannel("my-amf");
    cs.addChannel(pollingAMF);
    
    

Usually, there is no difference in the result of either of these options, but there are some properties that are set on the channel and used by the client code. When you create your channel using the first option, you should set the following properties depending on the type of channel you are creating: pollingEnabled and pollingIntervalMillis on AMFChannel and HTTPChannel, and connectTimeoutSeconds on Channel. So, when you create a polling AMFChannel on the client, you should set the pollingEnabled and pollingInterval properties, as the following example shows:

...
var cs:ChannelSet = new ChannelSet(); 
var pollingAMF:AMFChannel = new AMFChannel("my-amf",
    "http://servername:8400/eqa/messagebroker/amfpolling");
pollingAMF.pollingEnabled = true;
pollingAMF.pollingInterval = 8000;
cs.addChannel(pollingAMF);
...

The second option, using the ServerConfig.getChannel() method, retrieves these properties, so you do not need to set them in your client code. You should use this option when you use a configuration file to define channels with properties.

For components that use clustered destinations, you must define a ChannelSet and set the clustered property of the ChannelSet to true.

The following example shows MXML code for declaring a RemoteObject component and specifying a ChannelSet and Channel:

<RemoteObject id="ro" destination="Dest">
    <mx:channelSet>
        <mx:ChannelSet>
            <mx:channels>
                <mx:AMFChannel id="myAmf"
                    uri="http://myserver:2000/myapp/messagebroker/amf"/>
            </mx:channels>
        </mx:ChannelSet>
    </mx:channelSet>
</RemoteObject>

The following example shows equivalent ActionScript code:

private function run():void {
    ro = new RemoteObject();
    var cs:ChannelSet = new ChannelSet(); 
    cs.addChannel(new AMFChannel("myAmf", 
        "http://{server.name}:{server.port}/eqa/messagebroker/amf"));
    ro.destination = "RemotingDest_runtime"; 
    ro.channelSet = cs;
}

One slight difference is that when you declare your Channel in MXML, you cannot have the dash (-) character in the value of id attribute of the corresponding channel that is defined on the server. For example, you would not be able to use a channel with an id value of message-dest. This is not an issue when you use ActionScript instead of MXML.


Comments


No screen name said on Dec 14, 2008 at 11:03 AM :
These docs are fine, but show no method to create a JMS destination for a Consumer/Producer on the Flex side. One of the things that must be added is the properties, and there doesn't appear to be a way to do that easily.

I'm still trying to figure it out or I'd add code myself.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/blazeds/1/blazeds_devguide/runtimeconfig_5.html