`
feirou520
  • 浏览: 118621 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

ActiveMQ XML配置文件

    博客分类:
  • JMS
阅读更多

ActiveMQ包含了很多features(详见http://activemq.apache.org/features.html ), 
不同的需求,不同的环境,需要不同的features,当然需要不同的配置。在这里我只写了最基本的配置,算是抛砖了,希望引出更多关于ActiveMQ的高级配置。
假设已经正确安装ActiveMQ5.0,同时及其IP地址为192.168.1.148,具体使用时可以改为自己的IP。下面讲解的配置实现的features如下:

   1. 客户端可以通过tcp://192.168.1.148连接ActiveMQ。
   2. 消息持久化保存,重启服务器不会丢失消息。
   3. 可以通过http://192.168.1.148:8161/admin监控ActiveMQ服务器

配置

ActiveMQ默认使用的是XML格式配置,从4.0版本开始用MBean的方式实现XML配置,配置文件在${activemq.home}/conf目录下,文件名为activemq.xml。最新的默认配置见
http://svn.apache.org/repos/asf/activemq/trunk/assembly/src/release/conf/activemq.xml 。下面为本篇文章使用的配置,及重要部分的解释。

 

   1. <beans  
   2.   <SPAN class=hilite2>xml</SPAN>ns="http://www.springframework.org/schema/beans"  
   3.   <SPAN class=hilite2>xml</SPAN>ns:amq="http://<SPAN class=hilite1>activemq</SPAN>.org/config/1.0"  
   4.   <SPAN class=hilite2>xml</SPAN>ns:xsi="http://www.w3.org/2001/<SPAN class=hilite2>XML</SPAN>Schema-instance"  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd   
   5.   http://<SPAN class=hilite1>activemq</SPAN>.org/config/1.0 http://<SPAN class=hilite1>activemq</SPAN>.apache.org/schema/<SPAN class=hilite1>activemq</SPAN>-core.xsd   
   6.   http://<SPAN class=hilite1>activemq</SPAN>.apache.org/camel/schema/spring>  
   7.     
   8.   <!-- persistent="true"表示要持久化存储消息,和子元素persistenceAdapter结合使用 -->  
   9.   <!-- dataDirectory默认的存储持久化数据的目录 -->  
  10.   <!-- brokerName 设置broker的name,在注意在网络上必须是唯一的-->  
  11.   <!-- 更多参考http://<SPAN class=hilite1>activemq</SPAN>.apache.org /xbean-<SPAN class=hilite2>xml</SPAN>-reference-50.html#XBean<SPAN class=hilite2>XML</SPAN>Reference5.0-brokerelement -->  
  12.   <broker <SPAN class=hilite2>xml</SPAN>ns="http://<SPAN class=hilite1>activemq</SPAN>.org/config/1.0" brokerName="192.168.1.148" persistent ="true" dataDirectory="${<SPAN class=hilite1>activemq</SPAN>.base}/data" useShutdownHook="false">  
  13.     
  14.     <!-- Destination specific policies using destination names or wildcards -->  
  15.     <!-- wildcards意义见http://<SPAN class=hilite1>activemq</SPAN>.apache.org/wildcards.html -->  
  16.     <destinationPolicy>  
  17.       <policyMap>  
  18.         <policyEntries>  
  19.        <!-- 这里使用了wildcards,表示所有以EUCITA开头的topic -->  
  20.           <policyEntry topic="EUCITA.>" producerFlowControl="false" memoryLimit="10mb">  
  21.             <!-- 分发策略 -->  
  22.         <dispatchPolicy>  
  23.           <!-- 按顺序分发 -->  
  24.               <strictOrderDispatchPolicy/>  
  25.             </dispatchPolicy>  
  26.         <!--  恢复策略-->  
  27.             <subscriptionRecoveryPolicy>  
  28.           <!-- 只恢复最后一个message -->  
  29.               <lastImageSubscriptionRecoveryPolicy/>  
  30.             </subscriptionRecoveryPolicy>  
  31.           </policyEntry>  
  32.         </policyEntries>  
  33.       </policyMap>  
  34.     </destinationPolicy>  
  35.   
  36.     <!-- The transport connectors <SPAN class=hilite1>ActiveMQ</SPAN> will listen to -->  
  37.     <transportConnectors>  
  38.        <transportConnector name="openwire" uri="tcp://192.168.1.148:61616" discoveryUri="multicast://default"/>  
  39.        <transportConnector name="ssl"     uri="ssl://192.168.1.148:61617"/>  
  40.        <transportConnector name="stomp"   uri="stomp://192.168.1.148:61613"/>  
  41.        <transportConnector name="xmpp"    uri="xmpp://192.168.1.148:61222"/>  
  42.     </transportConnectors>  
  43.       
  44.     <!-- 消息持久化方式 -->  
  45.     <persistenceAdapter>  
  46.       <amqPersistenceAdapter directory="${<SPAN class=hilite1>activemq</SPAN>.base}/data"/>  
  47.     </persistenceAdapter>  
  48. </broker>  
  49.   
  50.   <!-- lets create a command agent to respond to message based admin commands on the <SPAN class=hilite1>ActiveMQ</SPAN>.Agent topic -->  
  51.     <commandAgent <SPAN class=hilite2>xml</SPAN>ns="http://<SPAN class=hilite1>activemq</SPAN>.org/config/1.0"/>  
  52.      
  53.   <!-- An embedded servlet engine for serving up the Admin console -->  
  54.   <jetty <SPAN class=hilite2>xml</SPAN>ns="http://mortbay.com/schemas/jetty/1.0">  
  55.     <connectors>  
  56.       <nioConnector port="8161" />  
  57.     </connectors>  
  58.   
  59.     <handlers>  
  60.       <webAppContext contextPath="/admin" resourceBase="${<SPAN class=hilite1>activemq</SPAN>.base}/webapps/admin" logUrlOnStart="true" />        
  61.       <webAppContext contextPath="/demo" resourceBase="${<SPAN class=hilite1>activemq</SPAN>.base}/webapps/demo" logUrlOnStart="true" />          
  62.     </handlers>  
  63.   </jetty>    
  64. </beans>  

 注释

关于XML配置中元素的具体信息可以参考http://activemq.apache.org/xbean-xml-reference-50.html 下面介绍本篇配置使用的一些重要元素。
DispathPolicy

ActiveMQ支持3中不同的分发策略(避免翻译了以后误解,这里用原文):

   1. <roundRobinDispatchPolicy>:Simple dispatch policy that sends a message to every subscription that matches the message.
   2. <simpleDispatchPolicy>:Simple dispatch policy that sends a message to every subscription that matches the message.
   3. <strictOrderDispatchPolicy>:Dispatch policy that causes every subscription to see messages in the same order.

SubscriptionRecoveryPolicy

ActiveMQ支持6种恢复策略,可以自行选择使用不同的策略

   1. <fixedCountSubscriptionRecoveryPolicy>: keep a fixed count of last messages.
   2. <fixedSizedSubscriptionRecoveryPolicy>: keep a fixed amount of memory available in RAM for message history which is evicted in time order.
   3. <lastImageSubscriptionRecoveryPolicy>:only keep the last message.
   4. <noSubscriptionRecoveryPolicy>:disable recovery of messages.
   5. <queryBasedSubscriptionRecoveryPolicy>:perform a user specific query mechanism to load any messages they may have missed.
   6. <timedSubscriptionRecoveryPolicy>:keep a timed buffer of messages around in memory and use that to recover new subscriptions.

PersistenceAdapter

http://activemq.apache.org/persistence 讲解了关于persistence的信息。ActiveMQ5.0使用AMQ Message Store 持久化消息,这种方式提供了很好的性能(The AMQ Message Store is an embeddable transactional message storage solution that is extremely fast and reliable.)默认使用该存储方式即可,如果想使用JDBC来存储,可以查找文档配置。
Summary

本篇文章只提供了基本配置信息。如果需要更多的文章,可以查看ActiveMQ的文档。

讲了安装和简单的配置,下一篇将介绍和Sping的整合,以及多个queue,多个topic,多个producer,多个consumer的配置,使用。

 

原贴地址:http://jinguo.iteye.com/blog/239885

分享到:
评论

相关推荐

    ActiveMQ的activemq.xml详细配置讲解

    **ActiveMQ的activemq.xml配置详解** ActiveMQ是Apache软件基金会开发的一个开源消息代理,它遵循Java消息服务(JMS)规范,提供可靠的消息传递功能。`activemq.xml`是ActiveMQ的核心配置文件,它定义了服务器的...

    activeMQ_spring简单案例(含XML配置)

    在XML配置文件中,我们可以定义如下的元素: ```xml &lt;bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"&gt; &lt;bean id="queueDestination" class="org.apache.activemq...

    ActiveMQ 配置文件详解

    **ActiveMQ配置文件详解** Apache ActiveMQ 是一个开源的消息中间件,它实现了多种消息协议,如JMS(Java Message Service)和AMQP(Advanced Message Queuing Protocol),并且广泛应用于分布式系统中,提供可靠的...

    文档对应activemq和配置文件

    - **activemq.xml**:这是ActiveMQ的主要配置文件,包含了服务器端口、持久化策略、网络连接、安全性等设置。 - **users.xml** 和 **groups.xml**:用于定义ActiveMQ用户的访问控制,包括用户名、密码和权限。 - **...

    activemq5配置文档

    - **配置文件**:ActiveMQ的配置主要通过`activemq.xml`文件进行,这个XML文件定义了服务器的启动参数、网络连接、消息存储和安全设置等。 - **Broker配置**:Broker是ActiveMQ的核心,配置中包括了broker的名称、...

    spring activeMQ-demo 配置

    2. **配置ActiveMQ**: 可以通过web管理界面(默认http://localhost:8161/admin)来创建Topic或Queue,也可以在配置文件(conf/activemq.xml)中预先配置。 **二、Spring配置** 1. **JMS配置**: 在Spring的配置文件...

    activemq spring 客户端配置

    2. 配置ActiveMQ连接工厂:在Spring的配置文件(如applicationContext.xml)中定义一个JMS连接工厂bean,指定ActiveMQ服务器的URL、用户名和密码。 ```xml &lt;bean id="connectionFactory" class="org.apache....

    ActiveMQ消息服务配置

    ActiveMQ支持主从集群模式,通过配置文件`activemq.xml`可以实现这一功能: 1. **配置Master Broker**:设置`waitForSlave`为`true`。 2. **配置Slave Broker**:设置`masterConnectorURL`指向Master Broker的连接...

    activemq-5.15.15 JDBC持久化mysql8.0+的activemq.xml.pdf

    标题中的“activemq-5.15.15 JDBC持久化mysql8.0+的activemq.xml”指的是Apache ActiveMQ的一个特定版本(5.15.15)配置文件,该配置文件用于实现消息队列的数据持久化,通过JDBC连接MySQL 8.0以上的版本。ActiveMQ...

    activemq集群配置文档

    1. **创建 ZooKeeper 文件夹**:在 `/usr/local/` 下创建 `zookeeper` 文件夹用于存放 ZooKeeper 的配置文件。 2. **解压并配置 ZooKeeper**:对于每个节点,都需要解压 ZooKeeper 的安装包,并配置相应的 `myid` ...

    spring配置activemq详解

    - 在Spring的XML配置文件(如`activemq-consumer.xml`和`activemq-producer.xml`)中,我们可以定义JMS的ConnectionFactory和Destination(队列或主题)。 - `activemq-consumer.xml`通常包含消息消费者的配置,...

    ActiveMQ Master/Slave 主从配置

    配置Master/Slave环节中,需要修改ActiveMQ配置文件activemq.xml,在其中添加数据源配置,并调整persistenceAdapter的设置以适应JDBC方式的持久化。配置文件修改完成后,需要将修改后的配置文件复制到另一台虚拟机的...

    activemq-dsls:一对用于在 Java 中使用 ActiveMQ 代理的 DSL

    它最初的创建是为了允许在单元测试中定义代理配置的简化机制,而无需求助于 ActiveMQ 的内部类,或者使用 ActiveMQ XML 配置文件创建许多相似但不同的代理配置。 注意:这些 DSL 处于 pre-alpha 的这个阶段。 验证...

    ActiveMQ使用SSL加密文件Demo

    - 修改 ActiveMQ 的配置文件 `activemq.xml`,找到 `&lt;transportConnectors&gt;` 节点,添加一个使用 SSL 的连接器。 - 设置 `useSSL` 为 `true`,并指定密钥库路径、类型以及密码。 3. **客户端配置** - 客户端也...

    Spring和ActiveMQ整合的完整实例

    我们可以使用ActiveMQ的XML配置或者通过Java代码来创建和管理消息代理。ActiveMQ的Broker服务负责接收、存储和转发消息,确保消息的可靠传输。 整合Spring和ActiveMQ的步骤大致如下: 1. **配置ActiveMQ**:首先,...

    tomcat下activemq之http配置

    总的来说,配置Tomcat下的ActiveMQ HTTP连接涉及到多个方面,包括XML配置文件的修改、Web控制台的部署、安全性的设置以及Stomp协议的使用。理解这些知识点,能帮助你在实际开发中有效利用ActiveMQ实现可靠的消息传递...

    activemq 配置说明与activemq入门讲解

    1. **配置文件**:ActiveMQ的主要配置文件是`conf/activemq.xml`。这个XML文件定义了ActiveMQ服务器的行为,包括监听端口、网络连接、存储策略、安全设置等。 2. **监听端口**:在`&lt;transportConnectors&gt;`元素下...

    Spring集成ActiveMQ配置

    在Spring的配置文件中,定义一个JMS连接工厂: ```xml &lt;bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"&gt; ``` 3. **创建消息模板**:Spring提供了JmsTemplate类,...

    JMS 使用 ActiveMQ 传送文件

    博主可能讨论了如何配置ActiveMQ服务器,以及如何通过JMS API创建消息,将文件内容封装到消息中,然后通过网络发送给其他应用程序进行接收和解包。 **标签:“源码 工具”** “源码”标签暗示这篇博文可能包含了...

Global site tag (gtag.js) - Google Analytics