Using Flex Builder 2 you will be able to build complete Flex applications powered by a ColdFusion backend. And you can build them even without using Flex Enterprise Services (FES for short).
But having said that, your application may indeed benefit from FES. We'll be exposing additional FES functionality in future betas, but for now we have made one important FES capability as simple to use as you'd expect from ColdFusion. I am referring to the ability to push content down to the Flash client without needing the client to poll or refresh on timed intervals. For example, a real-time auction application with price changes reflected as they occur, or a charting application plotting data in real-time, or a management application that shows you the status of users and sessions within your application. FES refers to this functionality as "publish-subscribe", clients can subscribe to a thread and when data is published they receive it automatically.
The ColdFusion hook into FES is via an event gateway (so yes, this will require ColdFusion Enterprise, and it will also work with the Developer Edition). When the ColdFusion/Flex Connectivity update is installed, a new gateway type called "FlexMessaging" will be added to ColdFusion. You can create instances of this new gateway type to communicate with FES (inbound and outbound).
To help you get started, the following is the simplest possible example of ColdFusion Flex communication via FES, an example of ColdFusion publishing and Flex consuming. It creates a simple HTML form used to post messages which then appear in real-time in a Flex Text box.
Here goes:
- This assumes that FES is installed and running (it should be configured and running before you start CF).
- If you have not yet done so, be sure to enable the CF adapter in flex-message-service.xml (in C:\fes2\jrun4\servers\default\samples\WEB-INF\flex if you used the default FES install), here is what one could look like (with commented out stuff removed):
<?xml version="1.0" encoding="UTF-8"?>
<service id="message-service" class="flex.messaging.services.MessageService"
messageTypes="flex.messaging.messages.AsyncMessage">
<!-- description of message-service configuration -->
<adapters>
<adapter-definition id="actionscript"
class="flex.messaging.services.messaging.adapters.ActionScriptAdapter"
default="true" />
<adapter-definition id="jms"
class="flex.messaging.services.messaging.adapters.JMSAdapter"/>
<adapter-definition id="cfgateway"
class="coldfusion.flex.CFEventGatewayAdapter"/>
</adapters>
<destination id="ColdFusionGateway">
<adapter ref="cfgateway" />
<properties>
<gatewayid>*</gatewayid>
<gatewayhost>127.0.0.1</gatewayhost>
</properties>
<channels>
<channel ref="my-amf"/>
<channel ref="my-rtmp"/>
<channel ref="my-polling-amf"/>
</channels>
</destination>
</service>
- It also assumes that you have a gateway defined in CF Admin named "Flex2CF" of type FlexMessaging (no config file is needed, and you can point to any CFC), and that that gateway is running.
- The following is a simple CFM file with a form that self-posts and submits to the gateway for processing:
<!--- If form submitted, send message --->
<cfif IsDefined("FORM.message")>
<cfset msg=StructNew()>
<cfset msg.body="#FORM.message#">
<cfset msg.destination="ColdFusionGateway">
<cfset ret=SendGatewayMessage("Flex2CF", msg)>
<cfif ret>
Message sent.
<cfelse>
Message failed.
</cfif>
<br />
</cfif>
<!--- Form --->
<cfform name="form1" action="#CGI.SCRIPT_NAME#">
Message:
<cfinput type="text" name="message">
<br />
<cfinput type="submit" name="sbmt" value="Send">
</cfform>
<!--- Set focus to form --->
<InvalidTag>
document.form1.message.focus();
</script>
- Create a new project in Flex Builder, be sure to select YES when asked if the project will be using Flex Enterprise Services, and create the project under the Flex default server samples folder (C:\fes2\jrun4\servers\default\samples\ if you are using the default installation).
- This is the entire Flex app. It is a simple text box which displays the received messages. It also shows the connection and subscription state at the bottom (they should generally both always be true).
<?xml version=
"1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml"
creationComplete="initApp()"> <mx:Script> <![CDATA[
import mx.messaging.events.*;
public function initApp()
{
consumer.subscribe();
}
private function messageHandler(event:MessageEvent)
{
t.text += event.message.body +
"\n";
}
]]>
</mx:Script> <mx:Consumer id="consumer" destination="ColdFusionGateway"
message="messageHandler(event)" /> <mx:Panel height="100%" width="100%"
title="ColdFusionGateway Messages"> <mx:Text id="t" height="100%" width="100%" /> <mx:ControlBar> <mx:Label text="Connected={consumer.connected}
Subscribed={consumer.subscribed}" /> </mx:ControlBar> </mx:Panel> </mx:Application>
Try it out. You should be able to type messages in the CF page in your web browser, and they'll show up in the Flex app.
Just kidding! I'm loving this stuff and I'm really into this latest build.
awesome posts today :)
--- Ben
this stuff makes me feel like a kid again ;-)
Let me first describe what my web application scenario looks like:
- I want to use CFMX 7+/Scorpio for the backend (services)
- For the client-side view I want to have the choice between Flash-based and native
browser-based (that is D(X)HTML + AJAX etc.)
- I want to serve many concurrent users (1,000, maybe even 10,000 and more) with (near)
realtime data push; and not only for delivering data centrally from the server, but also
for multi-user data exchange (not necessarily multimedia data)
Until now, I have considered using the Flash Media Server 2 (FMS 2) for accomplishing such
a web application breed; or maybe some other 3rd party multi-user servers.
Now with the advent of this Flex/ColdFusion solution (Mystic, Flex Enterprise Services,
Flex Data Services) I ask myself silently: What's the name of the game ? Which approach could
be best suited for my scenario from a technological/development standpoint AND a financial
standpoint ?
Could You please shed some light on this question ?
Best Regards
Kai Tischler aus Verl am schönen Ölbachstrand
On another note, the FlexMail sample application seems to be gone, along with all of the older showcase apps. Is there some secret place we can go to find those now? If not, could you host the FlexMail app again for us?
Thanks!
6dust
Kai, FES can do what you want. You may still want Flash Media Server, it depends on what you will be serving. FMS is better suited for streaming audio and video and the like. If what you need to send is data, generated by some back-end processing, then CF+FES may be exactly what you need. You'll see better clarification on FES vs. FMS shortly.
6dust, I'll have them put those examples back up.
--- Ben
--- Ben
Some of the older samples are still in the labs Subversion repository, but I didn't see FlexMail there though. See http://labs.macromedia.com/wiki/index.php/Source:get
And an error on my form indicating,
" Unable to find Flex adapter for destination "ColdFusionGateway" in the RMI registry on localhost."
Any thoughts? I haven't done much with eventgateways prior to this.
--- Ben
(When I try to run it now I get the "Could not resolve <mx:Application> to a component implementation.")
http://deepuverma.blogspot.com/2006/09/how-to-push...