32
Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman www.muddbrick.com

Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Embed Size (px)

Citation preview

Page 1: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES

Dan Blackman

www.muddbrick.com

Page 2: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Dan Blackman

• Founder and Senior Consultant – – Mudd Brick Inc, Dallas, Tx

• Certified Adobe Instructor – Flex, ColdFusion, Flash

• Experience – 12 Years ColdFusion, Flash and Flex

Page 3: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 4: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Data Persistence: The Why!?

Why use one over the other!?

Page 5: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 6: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Data Persistence: The Why

Page 7: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Data Persistence: The Why

Let’s take a look at Remote Object and the way it persists data

Page 8: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Introducing Live Cycle Data Services

A Quick Look at Live Cycle Data Services – The How?

Page 9: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 10: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Introducing Live Cycle Data Services

Page 11: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 12: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Push vs Pull Messaging

Huh?

Page 13: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 14: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Configuring Message Channel / Destination

Let’s hit the road running

Page 15: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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.

Page 16: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 17: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

<destination id="ColdFusionGateway"> <adapter ref="cfgateway" /> <channels> <channel ref=“my-cfamf"/>

<channel ref=“cf-polling-amf"/> </channels> </destination>

Configuring a Messaging Channel / Destination

Page 18: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 19: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Using the Message Service with ColdFusion Event GatewaysThe server side of things

Page 20: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 21: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 22: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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>

Page 23: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Configuring the Event GatewayThe server side of things continued

Page 24: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 25: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Configuring the Event Gateway

• Configure the Event Gateway after the CFC is created:

Page 26: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Producing and Consuming MessagesPassing Data from Client to Server and back again

Page 27: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 28: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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";

Page 29: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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

Page 30: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

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}”/>

Page 31: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Let’s Look at some code….

Chat ApplicationCollaborative ApplicationData Push Application in ColdFusion

Page 32: Exploring Real-time apps with ColdFusion and Blaze DS / Live Cycle Data Services ES Dan Blackman

Questions?

Dan BlackmanMudd Brick [email protected]

Evals – mobile.cfunited.com