ActiveMQ——XML参考

来源:互联网 发布:自学编程网 编辑:程序博客网 时间:2024/06/06 03:07

XML参考

ActiveMQ XML参考

此页包含到XML参考向导的链接和ActiveMQ发行版相伴的XML配置的模板文档。

相关方案

参考文档

参考

XML 模板

XML 模板命名空间

XBean XML Reference 4.1

Reference

http://activemq.apache.org/schema/core/activemq-core-4.1.2.xsd

http://activemq.org/config/1.0

XBean XML Reference 5.0

Reference

http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd

http://activemq.org/config/1.0

XBean XML Reference 5.1

Reference

http://activemq.apache.org/schema/core/activemq-core-5.1.0.xsd

http://activemq.apache.org/schema/core

XBean XML Reference 5.2

Reference

http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd

http://activemq.apache.org/schema/core

XBean XML Reference 5.3.0

Reference

http://activemq.apache.org/schema/core/activemq-core-5.3.0.xsd

http://activemq.apache.org/schema/core

XBean XML Reference 5.3.1

Reference

http://activemq.apache.org/schema/core/activemq-core-5.3.1.xsd

http://activemq.apache.org/schema/core

XBean XML Reference 5.3.2

Reference

http://activemq.apache.org/schema/core/activemq-core-5.3.2.xsd

http://activemq.apache.org/schema/core

XBean XML Reference 5.4.0

Reference

http://activemq.apache.org/schema/core/activemq-core-5.4.0.xsd

http://activemq.apache.org/schema/core

XBean XML Reference 5.4.1

Reference

http://activemq.apache.org/schema/core/activemq-core-5.4.1.xsd

http://activemq.apache.org/schema/core

XBean XML Reference 5.4.2

Reference

http://activemq.apache.org/schema/core/activemq-core-5.4.2.xsd

http://activemq.apache.org/schema/core

XBean XML Reference 5.5.0

Reference

http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd

http://activemq.apache.org/schema/core

 

在配置文件中使用XSD

如果你使用XBean来解析XML配置文件,XML验收是一个可选项,以便你不需指定XML模板的位置。可是如果你使用Spring2.0XML来处理和解析XML,那么你需要在你的XML文档中定义XSD的位置,因为Spring使用模板命名空间或模板位置来解析命名空间的处理

Unable to locate NamespaceHandler fornamespace [http://activemq.org/config/1.0]

你可以在XML中引用到一个指定版本的XSD,如下所示:

<beansxmlns="http://www.springframework.org/schema/beans"

   xmlns:amq="http://activemq.org/config/1.0"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="

       http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd

       http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-4.1.2.xsd">

或者你更喜欢用通用的XSD而不是指定版本号,如下所示:

<beansxmlns="http://www.springframework.org/schema/beans"

   xmlns:amq="http://activemq.org/config/1.0"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="

       http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd

       http://activemq.org/config/1.0 http://activemq.apache.org/schema/activemq-core.xsd">

如果你的IDE取不到这个XSD,那么你需要手动连接到指定的发行版中。可是意味着你不必在么个ActiveMQ的发行版中更新你的XML配置文件。因为它会使用在activemq-core.jar中绑定的XSD。

注意命名空间

如果你使用ActiveMQ5.0或更早的版本,你的XML命名空间定义应指向http://activemq.org/config/1.0。如果使用5.1或之后的版本,你的命名空间应指向http://activemq.apache.org/schema/core.。如下所示。

ActiveMQ5.2 example

<beansxmlns="http://www.springframework.org/schema/beans"

   xmlns:amq="http://activemq.apache.org/schema/core"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="

       http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans.xsd

       http://activemq.apache.org/schema/core

       http://activemq.apache.org/schema/core/activemq-core-5.2.0.xsd

   ">

</beans>

ActiveMQ5.0 example

<beansxmlns="http://www.springframework.org/schema/beans"

   xmlns:amq="http://activemq.org/config/1.0"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xsi:schemaLocation="

       http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans.xsd

       http://activemq.org/config/1.0

       http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd

   ">

</beans>

上面的两个例子几乎就是相同的,区别只在命名空间。你可以在activemq-dev主题:更改ActiveMQ的命名空间中找到更详细的信息。

模板验证-XML元素按字符顺序进行排序

注意:从ActiveMQ 5.4.2开始,你可以从命令行中输入xbean url参数来关闭验证。这允许你使用现存的xml配置文件。

bin/activemq consolexbean:conf/activemq.xml?validate=false

从ActiveMQ 5.4开始,在<broker>元素中的XML元素必须按照字符顺序进行排序。如果查看XSD文件,这好像没有什么变化,区别是从5.4开始,XML配置文件实际上针对XML目标进行验证。

例如:下面的XML配置文件在5.3.x没有问题。

<?xml version="1.0"?>

<beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd  

http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd     

http://camel.apache.org/schema/springhttp://camel.apache.org/schema/spring/camel-spring.xsd">

 

 <broker xmlns="http://activemq.apache.org/schema/core"brokerName="brokerB1"destroyApplicationContextOnStop="true">

   

   <plugins>

     <loggingBrokerPlugin/>

   </plugins>

   

   <persistenceAdapter>

     <kahaDB directory="${activemq.base}/data/kahadb"enableJournalDiskSyncs="false" indexWriteBatchSize="10000"indexCacheSize="1000"/>

   </persistenceAdapter>

   

   <destinationPolicy>

     <policyMap>

       <policyEntries>

         <policyEntry queue=">" producerFlowControl="true"memoryLimit="5mb">

           <deadLetterStrategy>

              <individualDeadLetterStrategyqueuePrefix="DLQ." useQueueForQueueMessages="true"/>

           </deadLetterStrategy>

         </policyEntry>

       </policyEntries>

     </policyMap>

    </destinationPolicy>

   

   <managementContext>

     <managementContext createConnector="false"/>

   </managementContext>

   

   <systemUsage>

     <systemUsage>

       <memoryUsage>

         <memoryUsage limit="420 mb"/>

       </memoryUsage>

       <storeUsage>

         <storeUsage limit="1 gb"/>

       </storeUsage>

       <tempUsage>

         <tempUsage limit="250 mb"/>

       </tempUsage>

     </systemUsage>

   </systemUsage>

   

   <transportConnectors>

     <transportConnector name="tcp" uri="tcp://0.0.0.0:61616"/>

   </transportConnectors>

   

 </broker>

 

</beans>

可是在5.4中,它会触发一个异常,如下所示:

Caused by: org.xml.sax.SAXParseException:cvc-complex-type.2.4.a: Invalid content was found starting with element'persistenceAdapter'. One of'{"http://activemq.apache.org/schema/core":producerSystemUsage,"http://activemq.apache.org/schema/core":proxyConnectors,"http://activemq.apache.org/schema/core":regionBroker,"http://activemq.apache.org/schema/core":services,"http://activemq.apache.org/schema/core":shutdownHooks,"http://activemq.apache.org/schema/core":sslContext,"http://activemq.apache.org/schema/core":systemUsage,"http://activemq.apache.org/schema/core":taskRunnerFactory,"http://activemq.apache.org/schema/core":tempDataStore, "http://activemq.apache.org/schema/core":transportConnectorURIs,"http://activemq.apache.org/schema/core":transportConnectors,WC[##other:"http://activemq.apache.org/schema/core"]}' is expected.

为避免在5.4中发生此类错误,只需简单的更改XML元素的顺序,以至它们是按照字符顺序进行排列的。例如下面的顺序排列。

<?xml version="1.0"?>

<beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd  

http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd     

http://camel.apache.org/schema/springhttp://camel.apache.org/schema/spring/camel-spring.xsd">

 

 <broker xmlns="http://activemq.apache.org/schema/core"brokerName="brokerB1"destroyApplicationContextOnStop="true">

   

   <destinationPolicy>

     <policyMap>

       <policyEntries>

         <policyEntry queue=">"producerFlowControl="true" memoryLimit="5mb">

           <deadLetterStrategy>

              <individualDeadLetterStrategyqueuePrefix="DLQ." useQueueForQueueMessages="true"/>

           </deadLetterStrategy>

         </policyEntry>

       </policyEntries>

     </policyMap>

   </destinationPolicy>

   

   <managementContext>

      <managementContextcreateConnector="false"/>

   </managementContext>

 

   <persistenceAdapter>

     <kahaDB directory="${activemq.base}/data/kahadb"enableJournalDiskSyncs="false" indexWriteBatchSize="10000"indexCacheSize="1000"/>

   </persistenceAdapter>

 

   <plugins>

     <loggingBrokerPlugin/>

   </plugins>

   

   <systemUsage>

     <systemUsage>

       <memoryUsage>

         <memoryUsage limit="420 mb"/>

       </memoryUsage>

       <storeUsage>

         <storeUsage limit="1 gb"/>

        </storeUsage>

       <tempUsage>

         <tempUsage limit="250 mb"/>

       </tempUsage>

     </systemUsage>

   </systemUsage>

   

   <transportConnectors>

     <transportConnector name="tcp" uri="tcp://0.0.0.0:61616"/>

   </transportConnectors>

   

 </broker>

 

</beans>

使用ActiveMQ的startup脚本可以容易的进行ActiveMQ 5.4的测试,如下所示:

$ cd $ACTIVEMQ_HOME
$ ./bin/activemq console xbean:file:/Users/bsnyder/SpringSource/clients/Finra/activemq-example-unordered.xml
INFO: Using default configuration
(you can configure options in one of these file: /etc/default/activemq/Users/bsnyder/.activemqrc)

INFO: Invoke the following command tocreate a configuration file
./bin/activemq setup [ /etc/default/activemq | /Users/bsnyder/.activemqrc ]

INFO: Using java'/System/Library/Frameworks/JavaVM.framework/Home/bin/java'
INFO: Starting in foreground, this is just for debugging purposes (stop processby pressing CTRL+C)
Java Runtime: Apple Inc. 1.6.0_20/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Heap sizes: current=258880k free=253106k max=258880k
JVM args: -Xms256M -Xmx256M-Dorg.apache.activemq.UseDedicatedTaskRunner=true -Djava.util.logging.config.file=logging.properties-Dcom.sun.management.jmxremote-Dactivemq.classpath=/Users/bsnyder/amq/apache-activemq-5.4.1/conf;-Dactivemq.home=/Users/bsnyder/amq/apache-activemq-5.4.1-Dactivemq.base=/Users/bsnyder/amq/apache-activemq-5.4.1
ACTIVEMQ_HOME: /Users/bsnyder/amq/apache-activemq-5.4.1
ACTIVEMQ_BASE: /Users/bsnyder/amq/apache-activemq-5.4.1
Loading message broker from: xbean:file:/Users/bsnyder/SpringSource/clients/Finra/activemq-example-unordered.xml
...


原创粉丝点击