320 likes | 557 Views
Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES. Dan Blackman www.muddbrick.com. Dan Blackman. Founder and Senior Consultant – Mudd Brick Inc, Dallas, Tx Certified Adobe Instructor – Flex, ColdFusion, Flash
E N D
Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman www.muddbrick.com
Dan Blackman • Founder and Senior Consultant – • Mudd Brick Inc, Dallas, Tx • Certified Adobe Instructor – Flex, ColdFusion, Flash • Experience – 12 Years ColdFusion, Flash and Flex
Objectives • Data Persistence: The Why!? • Introducing Live Cycle Data Services • Push vs Pull Messaging • Configuring Message Channel / Destination • Using the Message Service with ColdFusion Event Gateways • Configuring the Event Gateway • Producing and Consuming Messages • Summary and Questions
Data Persistence: The Why!? Why use one over the other!?
Data Persistence: The Why? • ColdFusion Request / Response Applications • Flex Rich Internet Applications • Persisted data is NOT refreshed automatically • Stateful approach to managing data – No more session variables • Refreshed through manual client interactions or Actionscript • Flex Real-time Applications • Persisted Data is refreshed via interactions with server • Stateful approach with server side synchronization • Refreshed through Polling, Long-Polling or RTMP • Data Management Service – Live Cycle service – provides data synchronization between Flex Clients
Data Persistence: The Why Let’s take a look at Remote Object and the way it persists data
Introducing Live Cycle Data Services A Quick Look at Live Cycle Data Services – The How?
Introducing Live Cycle Data Services • Live Cycle Data Services ES allows multiple applications to access data from the Flex Framework • Consists of : • Flex Messaging Service • Flex Data Management • Flex Proxy Service • Remote Object Service
Let’s review the Live Cycle Data Services Framework – ColdFusion 8 • Go to c:\ColdFusion8\wwwroot\WEB-INF • web.xml jrun configuration file • flex directory contains config files for LDS • classes directory location for compiled java classes • lib directory location for compiled .jar files
Push vs Pull Messaging • Many approaches to Data Access: • Simple AMF – Stateful Approach • Client Pull access initiated by user • RTMP – Real Time Messaging Protocol • Maintains persistent connection • Allows real-time communication • Uses Java-NIO facilities – Scalable Solution • Polling – Client Polling • Flex Client sends requests for messages periodically • Uses poll-wait-interval to set the time between requests • Less Scalable solution
Configuring Message Channel / Destination Let’s hit the road running
Configuring a Messaging Channel / Destination Determine how data is transferred to/ from the server by selecting an adapter. • Cfgateway: Messages sent between ColdFusion 8 and Flex Client • JMS adapter: Allows the use of both JMS and Flex clients to communicate • Actionscript Adapter: Flex Default adapter allows only Flex Clients to participate in communication.
Configuring a Messaging Channel / Destination • Most channels are configured out-of-the box • wwwroot/WEB-INF/flex/Services-config.xml • my-cf-amf • cf-polling-amf • cf-long-polling-amf • cf-streaming-amf • cf-rtmp
Configuring a Messaging Channel / Destination <destination id="ColdFusionGateway"> <adapter ref="cfgateway" /> <channels> <channel ref=“my-cfamf"/> <channel ref=“cf-polling-amf"/> </channels> </destination>
Let’s review the Live Cycle Data Services Framework – ColdFusion 8 • Go to c:\ColdFusion8\wwwroot\ • Go to the WEB-INF\flex directory • Open the services-config.xml and messaging-config.xml
Using the Message Service with ColdFusion Event Gateways The server side of things
Using ColdFusion Event Gateways • ColdFusion Event Gateways: • provide communication over protocols other than HTTP. • communicate with various kinds of clients (including Flex Clients). • Server requirements: • ColdFusion Enterprise Edition, version 7.02 or later • LiveCycle Data Services 2
Using ColdFusion Event Gateways • Start by creating a MessageGateway CFC: <cffunction name="onIncomingMessage" returntype="any"> <cfargument name="event" type="struct" required="true"> <!--- Code to handle the data from Flex Client ---> </cffunction> Use the data property to retrieve the data • event.data.body • event.data.headers
Using ColdFusion Event Gateways <cffunction name="sendToFlex" returntype="void" access="public"> <cfargument name=“dataToSend" type=“any" required="true"> <!--- Populate structure with data to send back to Flex. ---> <cfset messageOut.body = dataToSend> <cfset messageOut.headers = structNew()> <cfset messageOut.headers["user"]="ColdFusion"> <cfset messageOut.destination = "ColdFusionGateway"> <!--- Send the structure to Flex. ---> <cfset SendGatewayMessage(“MyAppGateway", messageOut)> </cffunction>
Configuring the Event Gateway The server side of things continued
Configuring the Event Gateway • Configure the Event Gateway after the MessageGateway CFC is created: • Open the ColdFusion Administrator and select Event Gateways > Gateway Instances. • Set the gateway properties as follows: • GatewayID: A unique string identifier • Gateway Type: DataServicesMessaging • CFC Path: The CFC file name and path • Startup Mode: Automatic
Configuring the Event Gateway • Configure the Event Gateway after the CFC is created:
Producing and Consuming Messages Passing Data from Client to Server and back again
Producing and Consuming Messages • Flex uses client-side components to handle publishing and consumption of messages • <mx:Producer …> • <mx:Consumer …> • Work together with messaging services in LCDS • Simply point the Producer and Consumer to a valid Destination
Producing and Consuming Messages • Two ways to Consume messages from a destination: • <mx:Consumer id=“consumer" • destination=“ColdFusionGateway“ message=“messageHandler(event)”/> • import mx.messaging.Consumer; • var crMessagingService:Consumer = new Consumer(); • consumer.destination = “ColdFusionGateway";
Receiving and Processing Mesages • Setting up Channel and Destination via Actionscript: public function initApp():void { • var channel:AMFChannel = new AMFChannel(“my-cf-amf", "http://127.0.0.1/flex2gateway/"); consumer = new Consumer(); cons.destination = "ColdFusionGateway"; cons.channelSet = new ChannelSet(); cons.channelSet.addChannel(sAMF); cons.addEventListener(MessageAckEvent.ACKNOWLEDGE, ackHandler); cons.addEventListener(MessageEvent.MESSAGE, messageHandler); cons.addEventListener(MessageFaultEvent.FAULT, faultHandler); cons.subscribe(); } Automatically dispatches a MessageEvent when a message is received
Sending and Receiving Complex Data • On the receiving end, handle the data through the messageHandler. public function handleNotificationsResult (event:MessageEvent):void { facebookNotifications = new XMLListCollection(event.message.body.channel..item); } <mx:DataGrid id=“dgNotifs” dataProvider=“{facebookNotifications}”/>
Let’s Look at some code….Chat ApplicationCollaborative ApplicationData Push Application in ColdFusion
Questions?Dan BlackmanMudd Brick Inc.dblackman@muddbrick.comEvals – mobile.cfunited.com