flex与java通信:blazeds配置文件

一、web.xml中对blazeds的配置

	<listener>
		<listener-class>flex.messaging.HttpFlexSession</listener-class>
	</listener>

<listener>用于将HttpFlexSession类作为监听器注册到web.xml中,这样系统就可以检测到J2EE HttpSession属性和代理属性的变化,进而通知FlexSession属性和目前绑定的listener做相应处理.


<servlet>
		<servlet-name>MessageBrokerServlet</servlet-name>
		<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
		<init-param>
			<param-name>services.configuration.file</param-name>
			<param-value>/WEB-INF/flex/services-config.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>MessageBrokerServlet</servlet-name>
		<url-pattern>/messagebroker/*</url-pattern>
	</servlet-mapping>

       其实现是基于一个叫flex.messaging.MessageBroker的Servlet。各种消息通道的配置都存在于WEB-INF\flex\services-config.xml及其包含的3个XML文件中。

          MessageBrokerServlet的Servlet将负责对对所有URL符合/messagebroker/*模式的请求进行处理,它会在Servlet容器启动时启动,并在启动时读取配置文件/WEB-INF/flex/services-config.xml.


	<login-config>
		<auth-method>BASIC</auth-method>
	</login-config>



1、service-config.xml

services-config.xml包含BlazedDS引用的服务文件,安全设置,通道定义,系统参数.

----------services

    <services>
        
        <service class="flex.samples.DatabaseCheckService" id="hsqldb" />
        <service-include file-path="remoting-config.xml" />
        <service-include file-path="proxy-config.xml" />
        <service-include file-path="messaging-config.xml" />
        
	<service class="flex.samples.runtimeconfig.EmployeeRuntimeRemotingDestination" id="runtime-employee-ro" />

    	<!-- 
    	Application level default channels. Application level default channels are 
    	necessary when a dynamic destination is being used by a service component
    	and no ChannelSet has been defined for the service component. In that case,
    	application level default channels will be used to contact the destination.
        -->   
        <default-channels>
           <channel ref="my-amf"/>
        </default-channels>
    
	</services>

----------remoting-config.xml配置的就是一个flex.messaging.services.RemotingService

<service id="remoting-service"
    class="flex.messaging.services.RemotingService"></service>

remoting-service的内容:

    <adapters>
        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
    </adapters>

    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>

    <destination id="product">
        <properties>
            <source>flex.samples.product.ProductService</source>
        </properties>
    </destination>
    ..............destinations

adapters为用户设置设配器

channel的ref属性表明引用了信息通道

destination设置服务终端的目的地

----------messaging-config.xml配置的就是一个flex.messaging.services.MessageService

<service id="message-service" class="flex.messaging.services.MessageService"></service>

messaging-service的内容:
    <adapters>
        <!-- Blazeds提供了两种消息适配器,actionscript和jms --><adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
        <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/>
    </adapters>
    
    <default-channels>
		<channel ref="my-streaming-amf"/>
		<channel ref="my-polling-amf"/>
    </default-channels>

    <destination id="market-data-feed">
        <properties>
            <server>
                <allow-subtopics>true</allow-subtopics>
                <subtopic-separator>.</subtopic-separator>s
            </server>
        </properties>
        <channels>
			<channel ref="my-polling-amf"/>
			<channel ref="my-streaming-amf"/>
            <channel ref="per-client-qos-polling-amf"/>
        </channels>        
    </destination>  
    ..............destinations

   










jms消息适配器。消息先发送到消息服务器上,flex端订阅消息,如果服务器上有消息在客户端就显示出来。消息服务器很多都是收费的,开源的有ActiveMQ、OPENJMS等。ActiveMQ 是Apache的产品,最流行的,能力强劲的开源消息总线。ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久的事情了,但是JMS在当今的J2EE应用中间仍然扮演着特殊的地位。blazeds的官方文档上的例子就是用的ActiveMQ作为消息服务器

其他: Blazeds的消息机制是采用不断的轮询实现的,因此性能不怎么好,并发数最大为100,LCDS的消息机制是采用java的NIO,最高并发数是1000,Blazeds和LCDS相比性能还是比较差的,不过***系统的用户数比较少的情况下,Blazeds还是可以的,毕竟,客户都是比较吝啬的,有免费的肯定不想掏钱买昂贵的LCDS。

这里将会进一步补充jms有关内容。

----------proxy-config.xml配置的就是一个flex.messaging.services.HTTPProxyService

<service id="proxy-service" class="flex.messaging.services.HTTPProxyService">
</service>

proxy-confige的内容:
    <properties>
        <connection-manager>
            <max-total-connections>100</max-total-connections>
            <default-max-connections-per-host>2</default-max-connections-per-host>
        </connection-manager>
        <allow-lax-ssl>true</allow-lax-ssl>
    </properties>

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

    <adapters>
        <adapter-definition id="http-proxy" class="flex.messaging.services.http.HTTPProxyAdapter" default="true"/>
        <adapter-definition id="soap-proxy" class="flex.messaging.services.http.SOAPProxyAdapter"/>
    </adapters>

    <destination id="DefaultHTTP">
		<properties>
		</properties>
    </destination>
    
    <destination id="ws-catalog">
        <properties>
            <wsdl>http://feeds.adobe.com/webservices/mxna2.cfc?wsdl</wsdl>
            <soap>*</soap>
        </properties>
        <adapter ref="soap-proxy"/>
    </destination>
	..............destinations







----------security

    <security>
        <security-constraint id="sample-users">
            <auth-method>Custom</auth-method>
            <roles>
                <role>sampleusers</role>
            </roles>
        </security-constraint>

		<login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>        
        <!-- Uncomment the correct app server
        <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
        <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>
        <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
        <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>        
        -->
    </security>

security为配置安全性选项,然而,为remoting-config.xml或message-config.xml中的service添加安全性选项也是可以的.目的是只有通过身份验证,并具有某些role的用户才可以访问相应的destination.

security-constraint为安全约束.可以为destination应用安全约束.定义的方式有两种:一种是引用,一种是在destination定义的内部声明安全约束.

----------redeploy

        <redeploy>
            <enabled>true</enabled>
            <watch-interval>20</watch-interval>
            <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>            
            <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
        </redeploy>

----------logging

    <logging>
        <!-- You may also use flex.messaging.log.ServletLogTarget -->
        <target class="flex.messaging.log.ConsoleTarget" level="Error">
            <properties>
                <prefix>[BlazeDS] </prefix>
                <includeDate>false</includeDate>
                <includeTime>false</includeTime>
                <includeLevel>true</includeLevel>
                <includeCategory>false</includeCategory>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
                <pattern>Service.*</pattern>
                <pattern>Configuration</pattern>
            </filters>
        </target>
    </logging>


<target>为日志信息的目标,默认的目标是控制台输出,即System.out(Java).
若要使用Servlet日志文件作为目标,将class属性改为"flex.messaging.log.ServletLogTarget".
level="Error"为日志的记录级别.有None,Error,Warn,Info,Debug,All六种选择.

<properties>为日志信息的显示格式.包括信息前缀(prefix)以及是否包含时间(includeTime),日期(includeDate),级别(includeLevel)或者类别.

<filters>为信息的过滤条件,只有匹配的类别才会被记录到指定的目标中.

----------channels

	<channels>
        <channel-definition id="per-client-qos-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/qosamfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>true</polling-enabled>
                <polling-interval-millis>500</polling-interval-millis>
                <flex-client-outbound-queue-processor class="flex.samples.qos.CustomDelayQueueProcessor">
                    <properties>
                        <flush-delay>5000</flush-delay>
                    </properties>
                </flex-client-outbound-queue-processor>
            </properties>
        </channel-definition>
	...............
    </channels>

channel-definition定义了Channel的标识及其实现类

endpoint定义了endpoint的实现类和Channel和Endpoint通信的url

Channel的作用就是帮助我们传输消息.Channel使用URL与Endpoint通信.Endpoint就是消息传输的接收器,它并不真正处理消息,它将处理过程委托给service.这样就分离了协议和消息类型这两个正交的关注点.Endpoint在接收到消息时会根据消息的destination获得合适的service,然后调用service.service.Message方法处理消息.BlazeDS定义了RemotingService,HttpProxyService,MessageService三类service,分别处理前端RemoteObject,HTTPService和WebService等组件发起的请求


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值