The ActiveMQ project site, 2004–2007 · independent archive
Independent historical archive. This site preserves the ActiveMQ project pages that were published at activemq.org in 2004–2007. It is not the project’s website and is not affiliated with or endorsed by the Apache Software Foundation. ActiveMQ and Apache are trademarks of the ASF. For current downloads and documentation go to activemq.apache.org.

Archive › Documentation › Using ActiveMQ › Xml Configuration

Archived page

Xml Configuration

Archived from http://www.activemq.org/site/xml-configuration.html, captured 2006-07-14 · view the capture · Added by James Strachan, last edited by James Strachan on Jun 12, 2006

We support an XML deployment descriptor for configurating the ActiveMQ Message Broker. There are many things which can be configured such as

  • transport connectors which consist of transport channels and wire formats TODO: add a link to a page explaining what transport connectors are how to configure and use them.
  • network connectors using network channels or discovery TODO: add a link to a page explaining what network connectors are how to configure and use them.
  • discovery agents TODO: add a link to a page explaining what discovery agents are how to configure and use them.
  • persistence providers & locations TODO: add a link to a page explaining what persistence providers are how to configure and use them.
  • custom message containers (such as last image caching etc)

So we decided that using XML would make this configuration much easier. From version 4.0 onwards we use XBean to perform the XML configuration.

For details of the XML see the Xml Reference

Be careful with broker names and URIs

Make sure you do not use any strange characters in the names of brokers as they are converted to URIs which do not allow things like underscores in them etc.

Examples

There are a number of examples of the XML configuration format. Here is a typical sample

<beans>

  <!-- Allows us to use system properties as variables in this configuration file -->
  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
  
  <broker useJmx="true" xmlns="http://activemq.org/config/1.0">
  
    <!--  Use the following to set the broker memory limit (in bytes)
    <memoryManager>  
        <usageManager id="memory-manager" limit="1048576"/>
    </memoryManager>
    -->
    
    <!-- Use the following to configure how ActiveMQ is exposed in JMX
    <managementContext>
       <managementContext connectorPort="1099" jmxDomainName="org.apache.activemq"/>
    </managementContext>
    -->

    <!-- In ActiveMQ 4, you can setup destination policies -->  
    <destinationPolicy>
      <policyMap><policyEntries>
        
          <policyEntry topic="FOO.>">
            <dispatchPolicy>
              <strictOrderDispatchPolicy />
            </dispatchPolicy>
            <subscriptionRecoveryPolicy>
              <lastImageSubscriptionRecoveryPolicy />
            </subscriptionRecoveryPolicy>
          </policyEntry>

      </policyEntries></policyMap>
    </destinationPolicy>
  
  
    <persistenceAdapter>
        <journaledJDBC journalLogFiles="5" dataDirectory="${activemq.home}/activemq-data"/>
      <!-- To use a different datasource, use the following syntax : -->
      <!-- 
      <journaledJDBC journalLogFiles="5" dataDirectory="../activemq-data" dataSource="#postgres-ds"/>
       -->
    </persistenceAdapter>
  
    <transportConnectors>
       <transportConnector name="default" uri="tcp://localhost:61616" discoveryUri="multicast://default"/>
       <transportConnector name="stomp"   uri="stomp://localhost:61613"/>
    </transportConnectors>
    
    <networkConnectors>
      <!-- by default just auto discover the other brokers -->
      <networkConnector name="default" uri="multicast://default"/>
      <!--
      <networkConnector name="host1 and host2" uri="static://(tcp://host1:61616,tcp://host2:61616)" failover="true"/>
      -->
    </networkConnectors>
    
  </broker>
  
  <!--  This xbean configuration file supports all the standard spring xml configuration options -->
  
  <!-- Postgres DataSource Sample Setup -->
  <!-- 
  <bean id="postgres-ds" class="org.postgresql.ds.PGPoolingDataSource">
    <property name="serverName" value="localhost"/>
    <property name="databaseName" value="activemq"/>
    <property name="portNumber" value="0"/>
    <property name="user" value="activemq"/>
    <property name="password" value="activemq"/>
    <property name="dataSourceName" value="postgres"/>
    <property name="initialConnections" value="1"/>
    <property name="maxConnections" value="10"/>
  </bean>
  -->
  
  <!-- MySql DataSource Sample Setup -->
  <!-- 
  <bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
    <property name="username" value="activemq"/>
    <property name="password" value="activemq"/>
    <property name="poolPreparedStatements" value="true"/>
  </bean>
  -->  
   
  <!-- Embedded Derby DataSource Sample Setup -->
  <!-- 
  <bean id="derby-ds" class="org.apache.derby.jdbc.EmbeddedDataSource">
    <property name="databaseName" value="derbydb"/>
    <property name="createDatabase" value="create"/>
  </bean>
  -->  

</beans>

From a binary distribution, from version 1.1 onwards there is an activemq script allowing you to run a Message Broker as a stand alone process from the command line easily providing the $ACTIVEMQ_HOME/bin directory is on your PATH.

AMQ 4.x

if myConfig.xml is in the classpath

activemq  xbean:myConfig.xml

or to use the file path system

activemq  xbean:file:../conf/myConfig.xml

AMQ 3.x

activemq myConfig.xml

Or to use the default config file its just

activemq

If you have a source distribution you can run a broker using Maven specifying one of these configuration files as follows
under the assembly module run :

maven server -Dconfig=xbean:file:src/release/conf/activemq.xml

If you're classpath is setup correctly you can achieve the same thing from the command line

java org.apache.activemq.broker.Main  xbean:file:src/release/conf/activemq.xml

Configuring embedded brokers

You can also use the XML Configuration to configure embedded brokers. For example using the JNDI configuration mechanism you can do the following
BrokerXmlConfigFromJNDITest
Or of you want to explicitly configure the embedded broker via Java code you can do the following
BrokerXmlConfigTest

Background

Since ActiveMQ has so many strategy pattern plugins for transports, wire formats, persistence and many other things, we wanted to leave the configuration format open so that you the developer can configure and extend ActiveMQ in any direction you wish.

So we use the Spring XML configuration file format, which allows any beans / POJOs to be wired together and configured. However often Spring's XML can be kinda verbose at times, so we have implemented an ActiveMQ extension to the Spring XML which knows about the common, standard ActiveMQ things you're likely to do (e.g. tags like connector, wireFormat, serverTransport, persistence) - but at any time you can fall back to the normal Spring way of doing things (with tags like bean, property etc).

This means that we have an ActiveMQ DTD which extends the Spring DTD which means DTD-aware XML editors can help you edit configuration files without you having to look at Java code to remember property and class names etc.

TODO: Add a link to the ActiveMQ DTD which actually extends the Spring DTD.

More from the archive