Flex Messaging with BEA Workshop Studio

by Jon Rose
01/29/2008

Abstract

This tutorial shows how to use Flex's LiveCycle Data Services Express (DS) messaging features to implement "data push" in your Flex applications with the BEA Workshop Studio (Flex bundle). My aim is to develop a small Flex messaging application that sends and receives messages.

Introduction To Flex Messaging

This tutorial demonstrates how to use messaging in Flex applications. The word "messaging" is rather generic, though. Here is how the Flex documentation defines the term:

Messaging systems let separate applications communicate asynchronously as peers by passing packets of data called messages back and forth through a Message Service. A message usually consists of a header and a body. The header contains an identifier and routing information. The body contains application data.

So, you will be building an application that allows you to asynchronously send data through the DS message service to our Flex client application. Here are some key DS messaging terms:

  • Producer: Producers are applications that create/send messages to the destination.
  • Consumer: Consumers are applications that receive messages from the destination.
  • Message Destination: Destinations are the resources used for both publish-subscribe and point-to-point messaging.
  • Message Channel: The channel is the method for connecting producers and consumers to the destination (using an endpoint).
  • Message Endpoint: An endpoint is the interface responsible for encoding and decoding data into messages.
  • Message Adaptor: The adaptor defines the messaging implementation. Options include using the ActionScriptAdapter provided with DS, or an external Java Message Service (JMS) provider.

DS provides a number of useful features including: durable message queues, security, and external message system integration. DS is deployed as a WAR file that runs in any Java EE Servlet container, like Apache Tomcat or BEA WebLogic. The ActionScriptAdapter message provider does not require any additional Java EE features. This tutorial covers the setup and configuration to implement a very basic messaging application.

Software Requirements

The following software products are used in this tutorial for building and running the messaging application:

An Overview of the Application

In this tutorial, you'll learn how to create a simple Flex producer and consumer client. The Flex user interface runs on the client side in the Flash Player, while DS is the server-side gateway for sending and receiving messages to the Flex client application.

Multiple Flex clients can send and receive messages from the same message queue. The producer user interface will allow you to send messages to the destination, and the consumer user interface will receive the messages created—therefore demonstrating the "data-push" features of DS, as messages appear on the screen without any custom polling code.

Figure 1 provides an overview of the source files. In particular, I'll be looking at:

  • services-config.xml : Defines usage of the messaging-config.xml file and the channel definition
  • messaging-config.xml: Defines the destination and adaptor
  • flex_client.mxml: Client code that creates and receives messages
Figure1
Figure 1. Overview of messaging files in the completed application (click for a larger view)

Now I'll look at how to create the application.

Step-By-Step Instructions for Building the Application

The following sections look at creating the Flex project, configuring the application, and, finally, deploying and running the application.

Setting up the IDE

Begin by downloading and installing the software in the Requirements section, and start BEA Workshop Studio. Next, create a new Flex Server project by importing the flex.war file. (This is installed with DS; you can get DS from the Requirements section.)

Now Select File→Import, and then select the WAR file option. Specify the location of the flex.war file that comes with DS (default windows location: C:\lcds\flex.war). Specify the name of the Web project as flex_server.

Finally, select Finish.

Figure2
Figure 2. Importing the flex.war file from DS

Configuring the Flex Server and the application

Next, you'll configure the flex_server application for messaging. Setting up the server-side application for messaging involves configuring the message channel, endpoint, destination, and adaptor.

  1. Edit the services-config.xml file. Edit the server-includes in the <services> section, so that only the messaging-config.xml is included as part of the configuration.
    
    <services> 
    
      <service-include file-path="messaging-config.xml" />        
    
    </services>
    
    
  2. Add the following to the <channel> section. This configures the messaging endpoint that is used to send and receive messages. The my-polling-amf channel created here will be used by the destination you'll configure in the messaging-config.xml file.
    
    <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
    
     <endpoint uri="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling"
    
               class="flex.messaging.endpoints.AMFEndpoint"/>
    
     <properties>
    
      <polling-enabled>true</polling-enabled>
    
      <polling-interval-seconds>1</polling-interval-seconds>
    
     </properties>
    
    </channel-definition>
    
    

    For your reference, here is the full services-config.xml file:

        
    
    <?xml version="1.0" encoding="UTF-8"?> 
    
    <services-config> 
    
       <services> 
    
           <service-include file-path="messaging-config.xml" />        
    
       </services> 
    
      
    
       <channels> 
    
           	<channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
    
       	<endpoint uri="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling"
    
       				class="flex.messaging.endpoints.AMFEndpoint"/>
    
       	<properties>
    
       		<polling-enabled>true</polling-enabled>
    
       		<polling-interval-seconds>1</polling-interval-seconds>
    
       	</properties>
    
       </channel-definition>
    
       </channels> 
    
      
    
       <logging> 
    
           <target class="flex.messaging.log.ConsoleTarget" level="Debug"> 
    
               <properties> 
    
                   <prefix>[Flex] </prefix> 
    
                   <includeDate>true</includeDate> 
    
                   <includeTime>true</includeTime> 
    
                   <includeLevel>true</includeLevel> 
    
                   <includeCategory>false</includeCategory> 
    
               </properties> 
    
               <filters> 
    
                   <pattern>Endpoint.*</pattern> 
    
                   <pattern>Service.*</pattern> 
    
                   <pattern>Configuration</pattern> 
    
               </filters> 
    
           </target> 
    
       </logging> 
    
      
    
       <system> 
    
           <redeploy> 
    
               <enabled>false</enabled> 
    
           </redeploy> 
    
       </system> 
    
      
    
    </services-config>
    
    
  3. Edit the messaging-config.xml file to configure the simple-topic destination, which is what the Flex Client application will reference for sending and receiving messages.
    1. Update the opening service tag to include the AsyncMessage class in the messageTypes.
    2. 
      <service id="message-service" 
      
      	    class="flex.messaging.services.MessageService"
      
      	    messageTypes="flex.messaging.messages.AsyncMessage">
      
      </service>	                     
      
      
    3. Create the simple-topic destination as a non-durable topic that uses the my-polling-amf channel defined in the services-config.xml file above. This is the message queue you'll send and receive messages with.
      
      <destination id="simple-topic">
      
        <properties>
      
        	<network>
      
        		<session-timeout>0</session-timeout>
      
        		<throttle-inbound policy="ERROR" max-frequency="50"/>
      
        		<throttle-outbound policy="REPLACE" max-frequency="500"/>
      
        	</network>
      
        	<server>
      
        		<durable>false</durable>
      
        	</server>
      
        </properties>
      
        <channels>
      
        	<channel ref="my-polling-amf"/>
      
        </channels>
      
      </destination>
      
      

    For your reference, here is the full messaging-config.xml file:

    
    <?xml version="1.0" encoding="UTF-8"?>
    
    <service id="message-service" 
    
       class="flex.messaging.services.MessageService"
    
       messageTypes="flex.messaging.messages.AsyncMessage">
    
       
    
       <adapters>
    
           <adapter-definition id="actionscript" 
    
           class="flex.messaging.services.messaging.adapters.ActionScriptAdapter"
    
           default="true" />
    
       </adapters>
    
       
    
       <destination id="simple-topic">
    
       	<properties>
    
       	   <network>
    
       	   	<session-timeout>0</session-timeout>
    
       	   	<throttle-inbound policy="ERROR" max-frequency="50"/>
    
       	   	<throttle-outbound policy="REPLACE" max-frequency="500"/>
    
       	   </network>
    
       	   <server>
    
       	   	<durable>false</durable>
    
       	   </server>
    
       	</properties>
    
       	<channels>
    
       		<channel ref="my-polling-amf"/>
    
       	</channels>
    
       </destination>
    
    </service>
    
    

Pages: 1, 2, 3

Next Page »

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy