BlazeDS Developer Guide

Using the Messaging Service

You use the Flex client-side API and the corresponding server-side Messaging Service to create messaging applications. Messaging lets a Flex application connect to a message destination on the server, send messages to the server, and receive messages from other messaging clients. Messages sent to the server are routed to other Flex applications that have subscribed to the same destination.

The server can also push messages to clients on its own. In the server push scenario, the server initiates the message and broadcasts it to a destination. All Flex applications that have subscribed to the destination receive the message. For an example, see the Trader Desktop sample application that ships with BlazeDS. For more information on the running the sample applications, see Running the BlazeDS sample applications.

The Messaging Service lets separate applications communicate asynchronously as peers by passing messages back and forth through the server. A message defines properties such as a unique identifier, BlazeDS headers, any custom headers, and a message body. The names of BlazeDS headers are prefixed by the string "DS".

The most well-known example of the type of application that can use the Messaging Service is an instant messaging application. In that application, one client sends a message to the server, and the server then routes the message to any subscribed clients. You can create other types of applications to implement broadcast messaging to simultaneously send messages to multiple clients, set up a system to send alert messages, or implement other types of messaging applications.

The following image shows the flow of messages from one Flex client to another. On the Flex client that sends the message, the message is routed over a channel to a destination on the server. The server then routes the message to other Flex clients, which perform any necessary processing of the received message.

Message producer and consumer diagram.

Client applications that send messages are called message producers. You define a producer in a Flex application by using the Producer component. Client applications that receive messages are called message consumers. You define a consumer in a Flex application by using the Consumer component.

Producers send messages to specific destinations on the server. A Consumer component subscribes to a server-side destination, and the server routes any messages sent to that destination to the consumer. In most messaging systems, producers and consumers do not know anything about each other.

A Flex application using the Messaging Service often contains at least one pair of Producer and Consumer components. This configuration enables each application to send messages to a destination and receive messages that other applications send to that destination.

Types of messaging

The Messaging Service supports publish-subscribe messaging. In publish-subscribe messaging, each message can have multiple consumers. You use this type of messaging when you want more than one consumer to receive the same message. Examples of applications that can use publish-subscribe messaging are auction sites, stock quote services, and other applications that require one message to be sent to many subscribers.

The Messaging Service lets you target messages to specific consumers that are subscribed to the same destination. Consumers can apply a selector expression to the message headers, or Producers and Consumers can add subtopic information to messages to target them. Therefore, even if multiple consumers are subscribed to the same destination, you can target a message to a single consumer or to a subset of all consumers. For more information, see Message filtering.

Note: You can support point-to-point messaging, also known as queue-based messaging, between Flex clients by using the JMSAdapter and bridging to a JMS queue. For more information, see Connecting to the Java Message Service (JMS).

The Messaging Service architecture

The components of the Messaging Service include channels, destinations, adapters, producers, and consumers. The following image shows the messaging architecture:

The messaging architecture

Channels

Flex applications can access the Message Service over several different message channels. The Flex client tries the channels in the order specified in the configuration files, until an available channel is found or all channels have been tried.

Each channel corresponds to a specific network protocol and has a corresponding server-side endpoint. Use a real-time channel with messaging. Real-time channels include AMFChannel and HTTPChannel with polling enabled, and StreamingAMFChannel and StreamingHTTPChannel. The AMF and HTTP channels with polling enabled poll the server for new messages when one or more Consumer components on the client have an active subscription.

Message Service

The Message Service maintains a list of message destinations and the clients subscribed to each destination. You configure the Message Service to transport messages over one or more channels, where each channel corresponds to a specific transport protocol.

Destinations

A destination is the server-side code that you connect to using Producer and Consumer components. When you define a destination, you reference one or more message channels that transport messages. You also reference a message adapter or use an adapter that is configured as the default adapter.

Adapters

BlazeDS provides two adapters to use with the Messaging Service and lets you create your own custom adapter:

  • The ActionScriptAdapter is the server-side code that facilitates messaging when your application uses ActionScript objects only or interacts with another system. The ActionScriptAdapter lets you use messaging with Flex clients as the sole producers and consumers of the messages.
  • The JMSAdapter lets you bridge destinations to JMS destinations, topics, or queues on a JMS server so that Flex clients can send messages to and receive messages from the JMS server.
  • A custom adapter lets you create an adapter to interact with other messaging implementations, or for situations where you need functionality not provided by either of the standard adapters.

You reference adapters and specify adapter-specific settings in a destination definition of the configuration files.

Messaging Service configuration

You configure the Messaging Service by editing the messaging-config.xml file or the services-config.xml file. As a best practice, use the messaging-config.xml file for your configuration to keep it separate from other types of configurations.

Within the services-config.xml file, you specify the channels to use with a destination, set properties of the destination, enable logging, configure security, and specify other properties. For more information, see Configuring the Messaging Service.


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/blazeds/1/blazeds_devguide/messaging_2.html