Thursday, February 09, 2012    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Feb 2006 >>
S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28        

Search

Categories
 • Acrobat (5) [RSS]
 • Adobe (110) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (39) [RSS]
 • AdobeMAX10 (34) [RSS]
 • AdobeMAX11 (27) [RSS]
 • AIR (297) [RSS]
 • Appearances (217) [RSS]
 • Books (86) [RSS]
 • CFEclipse (15) [RSS]
 • Cloud (1) [RSS]
 • ColdFusion (1477) [RSS]
 • ColdFusion Builder (22) [RSS]
 • Data Services (42) [RSS]
 • Fish Tank (5) [RSS]
 • Flash (356) [RSS]
 • Flex (562) [RSS]
 • Home Automation (5) [RSS]
 • HTML5 (23) [RSS]
 • JavaScript (2) [RSS]
 • Jobs (130) [RSS]
 • jQuery (14) [RSS]
 • JRun (14) [RSS]
 • Labs (62) [RSS]
 • LiveCycle (37) [RSS]
 • MAX (284) [RSS]
 • Mobile (239) [RSS]
 • Regular Expressions (19) [RSS]
 • RIA (21) [RSS]
 • SQL (45) [RSS]
 • Stuff (554) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (167) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
February 1, 2006

Getting Started With ColdFusion And Flex Enterprise Services

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:
  1. This assumes that FES is installed and running (it should be configured and running before you start CF).
  2. 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>
  3. 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.
  4. 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>
  5. 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).
  6. 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.

Comments
Ben, seriously, when are you going to write a book using ColdFusion and Flex? I mean... sheesh! You and your "jet-setting."

Just kidding! I'm loving this stuff and I'm really into this latest build.

awesome posts today :)
# Posted By jj | 2/1/06 4:15 PM
JJ, nope, no plans for a CF/Flex book. Well, not me personally. As much as I'd love to, honestly, I just don't have the bandwidth for it. Heck, I am months late on the two books I've been working on for ... um ... well ... er ... a long time. ;-)

--- Ben
# Posted By Ben Forta | 2/1/06 4:20 PM
ben, can FES install under a multiserver cf install (ie use that JRUN)? if so, any blow-by-blow?

this stuff makes me feel like a kid again ;-)
# Posted By PaulH | 2/2/06 3:14 AM
Hello Mr. Forta-Ben !

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
# Posted By Kai Tischler | 2/2/06 1:58 PM
Holy crap, this is awesome! I've been so sick of writing apps that need to check back with the sever for updates. It got better going from page refreshes to Iframes to AJAX, but still such a waste! I can't wait to try this stuff out.

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
# Posted By 6dust | 2/2/06 6:57 PM
Paul, yes, that is the plan, but I don't know if that is workign yet in the beta. I've been using the standalone install for now. So no blow-by-blow yet.

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
# Posted By Ben Forta | 2/2/06 9:26 PM
I am trying to get this set up locally on CF 7.0.2 Standard. Doesn't seem to work on CF Standard, correct?
# Posted By Stefan Richter | 2/3/06 4:20 AM
Stefan, FES integration is via Event Gateways which are not supported in CF Standard. I noted this in the original post.

--- Ben
# Posted By Ben Forta | 2/3/06 9:10 AM
I'm sorry, I must have missed that. This is a shame though as people like myself (who have CF Standard running locally) will have to go back to the Dev Install.
# Posted By Stefan Richter | 2/3/06 9:30 AM
6dust,

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:g...
# Posted By Erki Esken | 2/5/06 9:57 AM
I get false/false.

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.
# Posted By John Wilker | 2/22/06 1:54 PM
Ben, are you saying that the FES stuff won't work in its own JRun server instance in an existing JRun installation? I *have* to use the separate JRun installation for now? I ask because I installed FES and have it working on its own (http://127.0.0.1:8700/samples works), but the Mystic installer is choking on a "invalid JRun root directory" error and I can't install it. I'm just wondering if that tidbit is the source of my trouble. I have JRun installed at D:\JRun4 rather than C:\JRun4, and it doesn't seem to like that.
# Posted By Dave Carabetta | 3/9/06 5:00 PM
Dave, sure it will. You can use FES with an existing J2EE server, or just use the integrated JRun during the beta. I reccomend the latter for now only in that the configuration is simpler, and deploying any future betas will be easier too.

--- Ben
# Posted By Ben Forta | 3/9/06 9:11 PM
Bah, OK then...back to the drawing board. I simply cannot get the Mystic installer to recognize my D:\JRun4 location as a "valid JRun directory root." I posted to the forum set up through the Labs site, but didn't get any bites.
# Posted By Dave Carabetta | 3/10/06 10:33 AM
Ben - sorry to ask such a simple request, but do you think you could update this code for Beta 2? I had it working on our servers before we upgraded, and now I can't seem to get it to work even if I switch it to www.adobe.com/etc.

(When I try to run it now I get the "Could not resolve <mx:Application> to a component implementation.")
# Posted By Erin | 4/5/06 9:44 AM
If you want to push data from Coldfusion to Flex
http://deepuverma.blogspot.com/2006/09/how-to-push...
# Posted By jack | 9/16/06 12:38 PM
What does destination mean [destination="ColdFusionGateway"]? Is that the URL of the ColdFusion application? How do you tell flex where the server is?
# Posted By justin | 12/4/09 6:20 PM

  © Copyright 1997-2009 Ben Forta, All Rights Reserved