The NoteBook of EricKong

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks

Messages

All communication between Flex client components and BlazeDS is performed with messages. Flex components use several message types to communicate with their corresponding services in BlazeDS. All messages have client-side (ActionScript) implementations and server-side (Java) implementations because the messages are serialized and deserialized on both the client and the server. You can also create messages directly in Java and have those messages delivered to clients using the server push API.

Some message types, such as AcknowledgeMessage and CommandMessage, are used across different Flex components and BlazeDS services. Other message types are used by specific Flex components and BlazeDSservices. Forexample, to have a Producer component send a message to subscribed Consumer components, you create a message of type AsyncMessage and pass it to the send() method of the Producer component.

In other situations, you do not write code for constructing and sending messages. For example, you simply use a RemoteObject component to call the remote method from the Flex application. The RemoteObject component creates a RemotingMessage to encapsulate the RemoteObject call. In response it receives an AcknowledgeMessage from the server. The AcknowledgeMessage is encapsulated in a ResultEvent in the Flex application.

Sometimes you must create a message to send to the server. For example, you could send a message by creating an AsyncMessage and passing it to a Producer.

Services and destinations
Services and destinations are the next links in the message processing chain in the BlazeDS server. The system includes four services and their corresponding destinationsBlazeDS:
     RemotingService and RemotingDestination
     HTPProxyService and HTTPProxyDestination
     MessageService and MessageDestination
Services are the targets of messages from client-side Flex components. Think of destinations as instances of a service configured in a certain way. For example, a RemoteObject component is used on the Flex client to communicate with
the RemotingService. In the RemoteObject component, you must specify a destination id property that refers to a remoting destination with certain properties, such as the class you want to invoke methods on. The mapping
between client-side Flex components and BlazeDS services is as follows:
     HTTPService and WebService communicate with HTTPProxyService/HTTPProxyDestination
     RemoteObject communicates with RemotingService/RemotingDestination
     Producer and Consumer communicate with MessageService/MessageDestination
You can configure services and their destinations in the services-config.xml file, but it is best practice to put them in separate files as follows:
     RemotingService configured in the remoting-config.xml file
     HTTPProxyService configured in the proxy-config.xml file
     MessageService configured in the messaging-config.xml file

The following table describes the typical setup of the configuration files. Commented versions of these files are available in the resources/config directory of the BlazeDS installation.

Filename Description
services-config.xml  The top-level BlazeDS configuration file. This file usually contains security constraint definitions,channel definitions, and logging settings that each of the services can use. It can contain service definitions inline or include them by reference. Generally, the services are defined in the remoting-config.xml, proxy-config.xml, and messaging-config.xml.
remoting-config.xml The Remoting Service configuration file, which defines Remoting Service destinations for working with remote objects.
proxy-config.xml The Proxy Service configuration file, which defines Proxy Service destinations for working with web services and HTTP services (REST services).
messaging-config.xml The Messaging Service configuration file, which defines Messaging Service destinations for performing publish subscribe messaging.

The file-path value is relative to the location of the services-config.xml file. The following example shows service definitions included by reference:
<services>
<!-- REMOTING SERVICE -->
<service-include file-path="remoting-config.xml"/>
<!-- PROXY SERVICE -->
<service-include file-path="proxy-config.xml"/>
<!-- MESSAGE SERVICE -->
<service-include file-path="messaging-config.xml"/>
</services>

posted on 2011-06-29 15:40 Eric_jiang 阅读(316) 评论(0)  编辑  收藏 所属分类: Flex

只有注册用户登录后才能发表评论。


网站导航: