lcds学习笔记

1.在tomcat中配置flex的broker(代理服务server),服务中间件MOM采用activemq
Configure your web application so that it has access to the JMS server. For example, if you are using Tomcat, you
might have to add the following Resource definitions to the application to add support for Apache ActiveMQ, which
supports JMS version 1.1:

<Context docBase="${catalina.home}/../../apps/team" privileged="true"
antiResourceLocking="false" antiJARLocking="false" reloadable="true">
    <!-- Resourced needed for JMS -->
    <Resource name="jms/flex/TopicConnectionFactory"      注意与messaging-config中配置相同
        type="org.apache.activemq.ActiveMQConnectionFactory"
        description="JMS Connection Factory"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        brokerURL="vm://localhost"
        brokerName="LocalActiveMQBroker"/>
    <Resource name="jms/topic/flex/simpletopic"
        type="org.apache.activemq.command.ActiveMQTopic"
        description="my Topic"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        physicalName="FlexTopic"/>
    <Resource name="jms/flex/QueueConnectionFactory"
        type="org.apache.activemq.ActiveMQConnectionFactory"
        description="JMS Connection Factory"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        brokerURL="vm://localhost"
        brokerName="LocalActiveMQBroker"/>
     <Resource name="jms/queue/flex/simplequeue"
        type="org.apache.activemq.command.ActiveMQQueue"
        description="my Queue"
        factory="org.apache.activemq.jndi.JNDIReferenceFactory"
        physicalName="FlexQueue"/>
    <Valve className="flex.messaging.security.TomcatValve"/>
</Context>

The JMS server is often embedded in your J2EE server, but you can interact with a JMS server on a remote computer
accessed by using JNDI. For more information, see Using a remote JMS provider.

2.在messaging-config.xml中配置jmsAdapter(一般默认都有配置)
2.1<adapters>
    <adapter-definition id="jms"        
        class="flex.messaging.services.messaging.adapters.JMSAdapter"/>
</adapters>

2.2配置jmsAdapter的destination(Queue,Topic)
You perform most of the configuration of the JMSAdapter in the destination definition. Configure the adapter with the proper JNDI information and JMS ConnectionFactory information to look up the connection factory in JNDI.
The following example shows a destination that uses the JMSAdapter:

<destination id="chat-topic-jms">
    <properties>
    ...
        <jms>
            <destination-type>Topic</destination-type>    
            <message-type>javax.jms.TextMessage</message-type>
            <connection-factory>jms/flex/TopicConnectionFactory</connection-factory>
            <destination-jndi-name>jms/topic/flex/simpletopic</destination-jndi-name>
            <delivery-mode>NON_PERSISTENT</delivery-mode>
            <message-priority>DEFAULT_PRIORITY</message-priority>
            <preserve-jms-headers>"true"</preserve-jms-headers>
            <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>     
            <connection-credentials username="sampleuser" password="samplepassword"/>
            <max-producers>1</max-producers>
        </jms>
    </properties>
    ...
    <adapter ref="jms"/>
</destination>

几点说明:1.The PERSISTENT mode specifies that all sent messages be stored by the JMS server, and then forwarded to consumers. This configuration adds processing overhead but is necessary for guaranteed delivery. The NON_PERSISTENT mode does not require that messages be stored by the JMS server before forwarding to consumers, so they can be lost if the JMS server fails while processing the message. This setting is suitable for notification messages that do not require guaranteed delivery.
  
3.关于JMS server
方案1.embedded in a j2ee project,<amq:broker ....
方案2.独立的外部服务,如直接运行activemq。
   <!-- (Optional) JNDI environment. Use when using JMS on a remote JNDI server. -->
            <initial-context-environment>
                <property>
                    <name>Context.SECURITY_PRINCIPAL</name>
                    <value>anonymous</value>
                </property>
                <property>
                    <name>Context.SECURITY_CREDENTIALS</name>
                    <value>anonymous</value>
                </property>
                <property>
                    <name>Context.PROVIDER_URL</name>
                    <value>http://{server.name}:1856</value>
                </property>
                <property>
                    <name>Context.INITIAL_CONTEXT_FACTORY</name>
                    <value>fiorano.jms.runtime.naming.FioranoInitialContextFactory</value>
                </property>
            </initial-context-environment>
Flex treats name element values that begin with the text "Context." as constants defined by javax.naming
flex的jndi命名规则

If you do not specify the initial-context-environment properties in the jms section of a destination definition, the default JNDI environment is used.
The default JNDI environment is configured in a jndiprovider.properties application resource file and or a jndi.properties File

4.Message Service Config
<destination id="chat-topic">
    <properties>
        <network>
            <throttle-inbound policy="ERROR" max-frequency="50"/>       
            <throttle-outbound policy="ERROR" max-frequency="500"/>
        </network>
    </properties>
</destination>
客户端CLIENT的网络状态,这里设置了上限<subscription-timeout-minutes  ....
       <server>
            <message-time-to-live>0</message-time-to-live>
        </server>

你可能感兴趣的:(tomcat,jms,Flex,activemq,Security)