加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

About channels and endpoints

发布时间:2020-12-15 01:18:48 所属栏目:百科 来源:网络整理
导读:? About channels and endpoints ?关于信道与终端 View comments | RSS feed Channels are client-side objects that encapsulate the connection behavior between Flex components and the BlazeDS server. Channels communicate with corresponding endpo
?

About channels and endpoints

?关于信道与终端

View comments | RSS feed

Channels are client-side objects that encapsulate the connection behavior between Flex components and the BlazeDS server. Channels communicate with corresponding endpoints on the BlazeDS server. You configure the properties of a channel and its corresponding endpoint in the services-config.xml file.

信道是链接flex components和blazeds服务的客户端对象,信道可以与在BlazeDs服务器上的终端进行通信,你可以在services-config.xml文件中配置信道与它对象的终端

Configuring channels and endpoints

配置信道和终端

You configure channels in channel definitions in the services-config.xml file. The channel definition in the following example creates an AMFChannel that communicates with an AMFEndpoint on the server:

你可以在services-config.xml中以通道定义的方式配置通道.在下面的例子中的通道可以产生一个AMFChannel与服务器上的AMFEndpoint进行通信。

<channels>
...
<channel-definition id="samples-amf"
        type="mx.messaging.channels.AMFChannel">
        <endpoint url="http://servername:8400/myapp/messagebroker/amf"
            type="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>
</channels>

The channel-definition element specifies the following information:

该通道定义元素指定如下信息:

  • id and channel class type of the client-side channel that the Flex client uses to contact the server
  • id和type属性指定与服务器进行通信的客户端信道类型
  • endpoint element that contains the URL and endpoint class type of the server-side endpoint
  • 终端元素包含服务器的URL和type属性
  • properties element that contains channel and endpoint properties
  • 属性元素包含信道和终端的属性?

The endpoint URL is the specific network location that the endpoint is exposed at. The channel uses this value to connect to the endpoint and interact with it. The URL

终端URL是终端所在的确定网络地址。信道使用该值与终端进行链接和通信。在所有服务器产生的终端中这个URL必须是唯一的。这个URL属性指向MessageBrokerServlet

?must be unique across all endpoints exposed by the server. The url attribute points to the MessageBrokerServlet.

How channels are assigned to a Flex component

信道是如何被分配给flex组件

Flex components use channel sets,which contain one or more channels,to contact the server. You can automatically or manually create and assign a channel set to a

flex组件使用信道组(信道组包含一个或者多个信道)与服务器进行通信,你可以自动或者手动创建和分配一个信道给flex组件

Flex component. The channel allows the component to contact the endpoint,which forwards the request to the destination.

该信道允许组件与终端进行链接,从而将请求发送到目的地

If you compile an MXML file using the MXML compiler option -services pointing to the services-config.xml file,the component (RemoteObject,HTTPService,and so on)

如果你编译一个MXML文件指定了选项 -services 对应的services-config.xml文件,那么组件(RemoteObject,HTTPService等等)将被自动分配一个信道组,is automatically assigned a channel set that contains one or more appropriately configured channel instances. The configuration is based on the channel definition

该信道组包含一个或者多个适合配置好的信道实例。该配置是建立在信道定义基础上的,在配置文件中分配了一个目的地。或者,如果你没有在编译环境中使用-service选项

assigned to a destination in a configuration file. Alternatively,if you do not compile your application with the -services option or want to override the compiled-in

,想重写编译行为,你可以手动创建一个信道组在MXML或者ActionScript,分配一个或者多个信道,然后将该信道组指定给flex?组件

behavior,you can manually create a channel set in MXML or ActionScript,populate it with one or more channels,and then assign the channel set to the Flex component.

Application-level default channels are especially important when you want to use dynamically created destinations and you do not want to create and assign channel sets

当你想手动创建应用目的地,并且不想为你的动态目的地的flex?组件创建和分配信道组,那么应用级别的信道对这种应用是很重要的

to your Flex components that use the dynamic destination. In that case,application-level default channels are used. For more information,see Assigning channels and endpoints to a destination.

这种情况时应用级别的默认信道应该被使用。需要更多信息可以查看为目的地分配信道和终端

When you compile a Flex client application with the MXML compiler-services option,it contains all of the information from the configuration files that is needed for the client to connect to the server.

当你编译一个flex客户端应用带有编译环境-services选项,它包含客户端与服务端进行链接的所有必要配置信息

To manually create channels,you create your own channel set in MXML or ActionScript,add channels to it,and then assign the channel set to a component. This process

为了手动创建信道,你创建自己信道组在MXML或者ActionScript文件,在其中添加信道,然后分配在信道组给对应的组件,这个过程一般遵循如下的规则:

is common in the following situations:

  • You do not compile your MXML file using the -services MXML compiler option. This is useful when you do not want to hard code endpoint URLs into your compiled SWF files on the client.
  • 你在编译环境中没有使用 -services选项,当你不想使用硬代码将终端URL嵌入到你的为客户端编译的SWF文件中
  • You want to use a dynamically created destination (the destination is not in the services-config.xml file) with the run-time configuration feature. For more information,see Run-time configuration.
  • 你希望动态创建目的地,该目的地不在services-config.xml文件中,带有运行时的配置特征,需要更多信息,请查看运行时配置
  • You want to control in your client code the order of channels that a Flex component uses to connect to the server.
  • 你希望在你的客户端代码控制信道序列,该信道进行flex组件与服务器的通信

When you create and assign a channel set on the client,the client requires the correct channel type and endpoint URL to contact the server. The client does not specify

当你在客户端创建和分配一个信道组,客户端需要一个正确的信道类型和终端URL与服务器进行连接,客户端没有指定终端类进行请求的处理

the endpoint class that handles that request,but there must be a channel definition in the services-config.xml file that specifies the endpoint class to use with the specified endpoint URL.

但是必须在services-config.xml文件中有一个信道定义,它指定终端类和所使用的确定终端URL

The following example shows a RemoteObject component that defines a channel set and channel inline in MXML:

下面的例子显示了一个RemoteObject组件,定义了一个信道组和内联信道在MXML文件中:

...
<RemoteObject id="ro" destination="Dest">
    <mx:channelSet>
        <mx:ChannelSet>
            <mx:channels>
                <mx:AMFChannel id="myAmf"
                    uri="http://myserver:2000/myapp/messagebroker/amf"/>
            </mx:channels>
        </mx:ChannelSet>
    </mx:channelSet>
</RemoteObject>
...

The following example shows ActionScript code that is equivalent to the MXML code in the previous example:

下面显示的as脚本与前面例子中的MXML代码具有一样作用:

...
    private function run():void {
            ro = new RemoteObject();
            var cs:ChannelSet = new ChannelSet(); 
            cs.addChannel(new AMFChannel("myAmf","http://servname:2000/eqa/messagebroker/amf"));
            ro.destination = "Dest"; 
            ro.channelSet = cs;
    }
...

Important: When you create a channel on the client,you must still include a channel definition that specifies an endpoint class in the services-config.xml file. Otherwise,the message broker cannot pass a Flex client request to an endpoint.
特别注意,当你在客户端创建一个信道时候,包含一个信道定义,其中在services-config.xml中指定了终端类。否则the message broker不能将flex客户端的请求传递到终端

Assigning channels and endpoints to a destination

分配一个信道和终端给一个目的地

Settings in the BlazeDS configuration files determine the channels and endpoints from which a destination can accept messages,invocations,or data,except when you use the run-time configuration feature. The channels and endpoints are determined in one of the following ways:

在BlazeDS配置文件中的设置决定了从哪个信道组和终端中目的地地址可以接收到消息,头信息,数据,排除使用运行配置的这种情况。这些信道和终端是以下面的方式被决定的

  • If most of the destinations across all services use the same channels,you can define application-level default channels in the services-config.xml file,as the following example shows.

?????????? 如果多数的目的地跨越了所有服务使用一样的信道,那么定义一个应用级别的默认通道在services-config.xml文件中,如下面的例子所示:

Note: Using application-level default channels is a best practice whenever possible.
注意:使用应用级别的信道在任何一个可以使用的地方都是最佳的

<services-config ...>
...
    <default-channels>
        <channel ref="my-http"/>
        <channel ref="my-amf"/>
    </default-channels>
...

In this case,all destinations that do not define channels use a default channel. Destinations can override the default channel setting by specifying their own channels,and services can also override it by specifying their own default channels.

  • If most of the destinations in a service use the same channels,you can define service-level default channels,as the following example shows:
    <service ...>
    ...
        <default-channels>
            <channel ref="my-http"/>
            <channel ref="my-amf"/>
        </default-channels>
    ...
    
    

    In this case,all destinations in the service that do not explicitly specify their own channels use the default channel.

  • The destination definition can reference a channel inline,as the following example shows:
    <destination id="sampleVerbose">
        <channels>
            <channel ref="my-secure-amf"/>
        </channels>
    ...
    </destination>
    
    

    Fallback and failover behavior

  • 反馈和故障转移行为

    The primary reason that channels are contained in a channel set is to provide a fallback mechanism from one channel to the next listed in the channel set,and so on,in case the first choice is unable to establish a connection to the server. For example,you could define a channel set that falls back from a StreamingAMFChannel to an AMFChannel with polling enabled to work around network components such as web server connectors,HTTP proxies,or reverse proxies that could buffer chunked responses incorrectly.

    In addition to the fallback behavior that the channel set provides,the channel defines a failoverURIs property. This property lets you configure a channel in ActionScript that causes failover across this array of endpoint URLs when it tries to connect to its destination. The connection process involves searching for the first channel and trying to connect to it. If the attempt fails,and the channel defines failover URIs,each is attempted before the channel gives up and the channel set searches for the next available channel. If no channel in the set can connect,any pending unsent messages generate faults on the client.

    Choosing an endpoint

  • 选择一个终端

    BlazeDS provides the following servlet-based channel and endpoint combinations. A secure version of each of these channels/endpoints transports data over a secure HTTPS connection. The names of the secure channels and endpoints all start with the text "Secure"; for example,SecureAMFChannel and SecureAMFEndpoint.

    Servlet-based channel/endpoint classes

    Description

    AMFChannel/AMFEndpoint

    A simple channel/endpoint that transports data over HTTP in the binary AMF format in an asynchronous call and response model. Use for RPC requests/responses with RPC-style Flex components such as RemoteObject,and WebService. You can also configure a channel that uses this endpoint to repeatedly poll the endpoint for new messages. You can combine polling with a long wait interval for long polling,which handles near real-time communication.

    For more information,see Simple channels and endpoints.

    HTTPChannel/HTTPEndpoint

    Provides the same behavior as the AMF channel/endpoint,but transports data in the AMFX format,which is the text-based XML representation of AMF. Transport with this endpoint is not as fast as with the AMFEndpoint because of the overhead of text-based XML. Use when binary AMF is not an option in your environment.

    For more information,see Simple channels and endpoints.

    StreamingAMFChannel/StreamingAMFEndpoint

    Streams data in real time over the HTTP protocol in the binary AMF format. Use for real-time data services,such as the Messaging Service where streaming data is critical to performance.

    For more information,see Streaming AMF and HTTP channels.

    StreamingHTTPChannel/StreamingHTTPEndpoint

    Provides the same behavior model as the streaming AMF channel/endpoint,which is the text-based XML representation of AMF. Transport with this endpoint is not as fast as with the StreamingAMFEndpoint because of the overhead of text-based XML. Use when binary AMF is not an option in your environment.

    For more information,see Streaming AMF and HTTP channels

    区别就是AMFChannel/AMFEndpoint和StreamingAMFChannel/StreamingAMFEndpoint使用binary AMF format ,速度较快,另外两种使用the AMFX format速度较慢,前面两种是基本的通信,后面两种主要用于多媒体流间的通信

  • Choosing a channel

  • 选择一个信道

    Depending on your application requirements,you can use simple AMF or HTTP channels without polling or with piggybacking,polling,or long polling. You can also use streaming AMF or HTTP channels. The difference between AMF and HTTP channels is that AMF channels transport data in the binary AMF format and HTTP channels transport data in AMFX,the text-based XML representation of AMF. Because AMF channels provide better performance,use an HTTP channel instead of an AMF channel only when you have auditing or compliance requirements that preclude the use of binary data over your network or when you want the contents of messages to be easily readable over the network (on the wire).

    Non-polling AMF and HTTP channels

    You can use AMF and HTTP channels without polling for remote procedure call (RPC) services,such as remoting service calls,proxied HTTP service calls and web service requests. These scenarios do not require the client to poll for messages or the server to push messages to the client.

    Piggybacking on AMF and HTTP channels

    The piggybacking feature enables the transport of queued messages along with responses to any messages the client sends to the server over the channel. Piggybacking provides lightweight pseudo polling,where rather than the client channel polling the server on a fixed or adaptive interval,when the client sends a non-command message to the server (using a Producer or RemoteObject object),the server sends any pending data for client messaging or data management subscriptions along with the response to the client message.

    Piggybacking can also be used on a channel that has polling enabled but on a wide interval like 5 seconds or 10 seconds or more,in which case the application appears more responsive if the client is sending messages to the server. In this mode,the client sends a poll request along with any messages it sends to the server between its regularly scheduled poll requests. The channel piggybacks a poll request along with the message being sent,and the server piggybacks any pending messages for the client along with the acknowledge response to the client message.

    Polling AMF and HTTP channels

    AMF and HTTP channels support simple polling mechanisms that clients can use to request messages from the server at set intervals. A polling AMF or HTTP channel is useful when other options such as long polling or streaming channels are not acceptable and also as a fallback channel when a first choice,such as a streaming channel,is unavailable at run time.

    Long polling AMF and HTTP channels

    You can use AMF and HTTP channels in long polling mode to get pushed messages to the client when the other more efficient and real-time mechanisms are not suitable. This mechanism uses the normal application server HTTP request processing logic and works with typical J2EE deployment architectures.

    You can establish long polling for any channel that uses a non-streaming AMF or HTTP endpoint by setting the polling-enabled,polling-interval-millis,wait-interval-millis,and client-wait-interval-millis properties in a channel definition; for more information,see Simple channels and endpoints.

    Streaming channels

    For streaming,you can use streaming AMF or HTTP channels. Streaming AMF and HTTP channels work with streaming AMF or HTTP endpoints.

    For more information about endpoints,see Choosing an endpoint.

  • (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读