mirror of https://github.com/apache/activemq.git
resolve https://issues.apache.org/activemq/browse/AMQ-2599 - tidy up exmple config to make it compliant with the schema - added simpe schema validation test and extended the broker start test, mvn test in assembly will now validate all the configs. added destroyApplicationContextOnStop to ensure jetty and other additions to the context are cleaned up when broker stops, allows mulitple brokers to rerun in the same jvm
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@910238 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a65881cf4e
commit
d3fb1aabce
|
@ -598,7 +598,7 @@ public class BrokerService implements Service {
|
|||
stopper.throwFirstException();
|
||||
}
|
||||
|
||||
public boolean checkQueueSize(String queueName) {
|
||||
public boolean checkQueueSize(String queueName) {
|
||||
long count = 0;
|
||||
long queueSize = 0;
|
||||
Map<ActiveMQDestination, Destination> destinationMap = regionBroker.getDestinationMap();
|
||||
|
|
|
@ -88,8 +88,8 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve
|
|||
protected static final Scheduler scheduler = Scheduler.getInstance();
|
||||
private static final Log LOG = LogFactory.getLog(JournalPersistenceAdapter.class);
|
||||
|
||||
private final Journal journal;
|
||||
private final PersistenceAdapter longTermPersistence;
|
||||
private Journal journal;
|
||||
private PersistenceAdapter longTermPersistence;
|
||||
|
||||
private final WireFormat wireFormat = new OpenWireFormat();
|
||||
|
||||
|
@ -114,20 +114,27 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve
|
|||
|
||||
private final Runnable periodicCheckpointTask = createPeriodicCheckpointTask();
|
||||
|
||||
private TaskRunnerFactory taskRunnerFactory;
|
||||
|
||||
public JournalPersistenceAdapter(Journal journal, PersistenceAdapter longTermPersistence, TaskRunnerFactory taskRunnerFactory) throws IOException {
|
||||
|
||||
this.journal = journal;
|
||||
journal.setJournalEventListener(this);
|
||||
|
||||
checkpointTask = taskRunnerFactory.createTaskRunner(new Task() {
|
||||
public boolean iterate() {
|
||||
return doCheckpoint();
|
||||
}
|
||||
}, "ActiveMQ Journal Checkpoint Worker");
|
||||
|
||||
this.longTermPersistence = longTermPersistence;
|
||||
setJournal(journal);
|
||||
setTaskRunnerFactory(taskRunnerFactory);
|
||||
setPersistenceAdapter(longTermPersistence);
|
||||
}
|
||||
|
||||
public void setTaskRunnerFactory(TaskRunnerFactory taskRunnerFactory) {
|
||||
this.taskRunnerFactory = taskRunnerFactory;
|
||||
}
|
||||
|
||||
public void setJournal(Journal journal) {
|
||||
this.journal = journal;
|
||||
journal.setJournalEventListener(this);
|
||||
}
|
||||
|
||||
public void setPersistenceAdapter(PersistenceAdapter longTermPersistence) {
|
||||
this.longTermPersistence = longTermPersistence;
|
||||
}
|
||||
|
||||
final Runnable createPeriodicCheckpointTask() {
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
|
@ -229,6 +236,12 @@ public class JournalPersistenceAdapter implements PersistenceAdapter, JournalEve
|
|||
return;
|
||||
}
|
||||
|
||||
checkpointTask = taskRunnerFactory.createTaskRunner(new Task() {
|
||||
public boolean iterate() {
|
||||
return doCheckpoint();
|
||||
}
|
||||
}, "ActiveMQ Journal Checkpoint Worker");
|
||||
|
||||
checkpointExecutor = new ThreadPoolExecutor(maxCheckpointWorkers, maxCheckpointWorkers, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
|
||||
public Thread newThread(Runnable runable) {
|
||||
Thread t = new Thread(runable, "Journal checkpoint worker");
|
||||
|
|
|
@ -195,4 +195,10 @@ public class MemoryPersistenceAdapter implements PersistenceAdapter {
|
|||
public long size(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setCreateTransactionStore(boolean create) throws IOException {
|
||||
if (create) {
|
||||
createTransactionStore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,13 @@ import java.io.IOException;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.usage.SystemUsage;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleException;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
@ -53,7 +52,24 @@ public class XBeanBrokerService extends BrokerService implements ApplicationCont
|
|||
private boolean start = true;
|
||||
private ApplicationContext applicationContext = null;
|
||||
private boolean destroyApplicationContextOnShutdown = false;
|
||||
private boolean destroyApplicationContextOnStop = false;
|
||||
|
||||
Runnable stopContextRunnable = new Runnable() {
|
||||
public void run() {
|
||||
if (applicationContext instanceof ConfigurableApplicationContext) {
|
||||
((ConfigurableApplicationContext) applicationContext).close();
|
||||
}
|
||||
if (applicationContext instanceof OsgiBundleXmlApplicationContext){
|
||||
try {
|
||||
((OsgiBundleXmlApplicationContext)applicationContext).getBundle().stop();
|
||||
} catch (BundleException e) {
|
||||
LOG.info("Error stopping OSGi bundle " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public XBeanBrokerService() {
|
||||
}
|
||||
|
||||
|
@ -69,21 +85,7 @@ public class XBeanBrokerService extends BrokerService implements ApplicationCont
|
|||
start();
|
||||
}
|
||||
if (destroyApplicationContextOnShutdown) {
|
||||
addShutdownHook(new Runnable() {
|
||||
public void run() {
|
||||
if (applicationContext instanceof ConfigurableApplicationContext) {
|
||||
((ConfigurableApplicationContext) applicationContext).close();
|
||||
}
|
||||
if (applicationContext instanceof OsgiBundleXmlApplicationContext){
|
||||
try {
|
||||
((OsgiBundleXmlApplicationContext)applicationContext).getBundle().stop();
|
||||
} catch (BundleException e) {
|
||||
LOG.info("Error stopping OSGi bundle " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
addShutdownHook(stopContextRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,9 +109,15 @@ public class XBeanBrokerService extends BrokerService implements ApplicationCont
|
|||
stop();
|
||||
}
|
||||
|
||||
public boolean isStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
if (destroyApplicationContextOnStop) {
|
||||
stopContextRunnable.run();
|
||||
}
|
||||
super.stop();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether or not the broker is started along with the ApplicationContext it is defined within.
|
||||
|
@ -121,12 +129,20 @@ public class XBeanBrokerService extends BrokerService implements ApplicationCont
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets whether the broker should shutdown the ApplicationContext when the broker is stopped.
|
||||
* Sets whether the broker should shutdown the ApplicationContext when the broker jvm is shutdown.
|
||||
* The broker can be stopped because the underlying JDBC store is unavailable for example.
|
||||
*/
|
||||
public void setDestroyApplicationContextOnShutdown(boolean destroy) {
|
||||
this.destroyApplicationContextOnShutdown = destroy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the broker should shutdown the ApplicationContext when the broker is stopped.
|
||||
* The broker can be stopped because the underlying JDBC store is unavailable for example.
|
||||
*/
|
||||
public void setDestroyApplicationContextOnStop(boolean destroy) {
|
||||
this.destroyApplicationContextOnStop = destroy;
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
|
|
|
@ -322,6 +322,11 @@
|
|||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- dependencies specific to this module -->
|
||||
<dependency>
|
||||
|
@ -367,9 +372,18 @@
|
|||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>validate-config</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -414,6 +428,30 @@
|
|||
<url>broker:(tcp://localhost:61616)?useJmx=false</url>
|
||||
</configuration>
|
||||
</plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-conf</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target/conf</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/release/conf</directory>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/sample-conf</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
|
|
@ -31,31 +31,8 @@
|
|||
<!--
|
||||
The <broker> element is used to configure the ActiveMQ broker.
|
||||
-->
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.base}/data">
|
||||
|
||||
<!--
|
||||
The managementContext is used to configure how ActiveMQ is exposed in
|
||||
JMX. By default, ActiveMQ uses the MBean server that is started by
|
||||
the JVM. For more information, see:
|
||||
|
||||
http://activemq.apache.org/jmx.html
|
||||
-->
|
||||
<managementContext>
|
||||
<managementContext createConnector="false"/>
|
||||
</managementContext>
|
||||
|
||||
<!--
|
||||
Configure message persistence for the broker. The default persistence
|
||||
mechanism is the KahaDB store (identified by the kahaDB tag).
|
||||
For more information, see:
|
||||
|
||||
http://activemq.apache.org/persistence.html
|
||||
-->
|
||||
<persistenceAdapter>
|
||||
<kahaDB directory="${activemq.base}/data/kahadb"/>
|
||||
</persistenceAdapter>
|
||||
|
||||
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.base}/data" destroyApplicationContextOnStop="true">
|
||||
|
||||
<!--
|
||||
For better performances use VM cursor and small memory limit.
|
||||
For more information, see:
|
||||
|
@ -90,7 +67,31 @@
|
|||
</policyMap>
|
||||
</destinationPolicy>
|
||||
|
||||
<!--
|
||||
|
||||
<!--
|
||||
The managementContext is used to configure how ActiveMQ is exposed in
|
||||
JMX. By default, ActiveMQ uses the MBean server that is started by
|
||||
the JVM. For more information, see:
|
||||
|
||||
http://activemq.apache.org/jmx.html
|
||||
-->
|
||||
<managementContext>
|
||||
<managementContext createConnector="false"/>
|
||||
</managementContext>
|
||||
|
||||
<!--
|
||||
Configure message persistence for the broker. The default persistence
|
||||
mechanism is the KahaDB store (identified by the kahaDB tag).
|
||||
For more information, see:
|
||||
|
||||
http://activemq.apache.org/persistence.html
|
||||
-->
|
||||
<persistenceAdapter>
|
||||
<kahaDB directory="${activemq.base}/data/kahadb"/>
|
||||
</persistenceAdapter>
|
||||
|
||||
|
||||
<!--
|
||||
The systemUsage controls the maximum amount of space the broker will
|
||||
use before slowing down producers. For more information, see:
|
||||
|
||||
|
|
|
@ -26,13 +26,16 @@
|
|||
e.g. <import resource="camel.xml"/>
|
||||
-->
|
||||
<beans
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
|
||||
|
||||
<!-- You can use a <packages> element for each root package to search for Java routes -->
|
||||
<packageScan>
|
||||
<packages>org.foo.bar</packages>
|
||||
<package>org.foo.bar</package>
|
||||
</packageScan>
|
||||
|
||||
<!-- You can use Spring XML syntax to define the routes here using the <route> element -->
|
||||
|
|
|
@ -25,7 +25,16 @@
|
|||
|
||||
e.g. $ bin/activemq xbean:conf/activemq-command.xml
|
||||
-->
|
||||
<beans>
|
||||
<beans
|
||||
xmlns="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-2.0.xsd
|
||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||
|
||||
<!-- Allows us to use system properties as variables in this configuration file -->
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
|
||||
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="command-broker" dataDirectory="${activemq.base}/data">
|
||||
<managementContext>
|
||||
<managementContext createConnector="true"/>
|
||||
|
@ -34,6 +43,7 @@
|
|||
<transportConnectors>
|
||||
<!-- Create a XMPP transport for XMPP clients. -->
|
||||
<transportConnector name="xmpp" uri="xmpp://localhost:61222"/>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
|
||||
</transportConnectors>
|
||||
</broker>
|
||||
|
||||
|
|
|
@ -23,11 +23,10 @@
|
|||
-->
|
||||
<beans
|
||||
xmlns="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-2.0.xsd
|
||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
|
||||
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<!--
|
||||
Allows us to use system properties as variables in this configuration
|
||||
|
@ -48,7 +47,7 @@
|
|||
- Change the brokerName attribute to something unique
|
||||
-->
|
||||
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="amq-broker" useJmx="true">
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="amq-broker" useJmx="true" destroyApplicationContextOnStop="true">
|
||||
|
||||
<!--
|
||||
Examples of destination-specific policies using destination
|
||||
|
@ -139,9 +138,9 @@
|
|||
Configure the following if you wish to use journaled JDBC for message
|
||||
persistence.
|
||||
|
||||
<persistenceAdapter>
|
||||
<persistenceFactory>
|
||||
<journaledJDBC dataDirectory="${activemq.base}/data" dataSource="#postgres-ds"/>
|
||||
</persistenceAdapter>
|
||||
</persistenceFactory>
|
||||
-->
|
||||
|
||||
<!--
|
||||
|
@ -214,35 +213,18 @@
|
|||
|
||||
http://activemq.apache.org/enterprise-integration-patterns.html
|
||||
-->
|
||||
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
|
||||
<import resource="camel.xml"/>
|
||||
|
||||
<!-- You can use a <package> element for each root package to search for Java routes -->
|
||||
<package>org.foo.bar</package>
|
||||
|
||||
<!-- You can use Spring XML syntax to define the routes here using the <route> element -->
|
||||
<route>
|
||||
<from uri="activemq:example.A"/>
|
||||
<to uri="activemq:example.B"/>
|
||||
</route>
|
||||
</camelContext>
|
||||
|
||||
<!--
|
||||
Lets configure some Camel endpoints
|
||||
|
||||
http://activemq.apache.org/camel/components.html
|
||||
<!--
|
||||
An embedded servlet engine for serving up the Admin console and other demos.
|
||||
For more information, see:
|
||||
|
||||
http://activemq.apache.org/web-console.html
|
||||
-->
|
||||
|
||||
<!-- configure the camel activemq component to use the current broker -->
|
||||
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
|
||||
<property name="connectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL" value="vm://localhost?create=false&waitForStart=10000" />
|
||||
<property name="userName" value="${activemq.username}"/>
|
||||
<property name="password" value="${activemq.password}"/>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<import resource="jetty.xml"/>
|
||||
|
||||
|
||||
<!--
|
||||
Uncomment to create a command agent to respond to message based admin
|
||||
commands on the ActiveMQ.Agent topic. For more information, see:
|
||||
|
@ -253,24 +235,6 @@
|
|||
-->
|
||||
|
||||
|
||||
<!--
|
||||
An embedded servlet engine for serving up the Admin console and other demos.
|
||||
For more information, see:
|
||||
|
||||
http://activemq.apache.org/web-console.html
|
||||
-->
|
||||
<jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
|
||||
<connectors>
|
||||
<nioConnector port="8161"/>
|
||||
</connectors>
|
||||
|
||||
<handlers>
|
||||
<webAppContext contextPath="/admin" resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
|
||||
<webAppContext contextPath="/demo" resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true"/>
|
||||
<webAppContext contextPath="/fileserver" resourceBase="${activemq.base}/webapps/fileserver" logUrlOnStart="true"/>
|
||||
</handlers>
|
||||
</jetty>
|
||||
|
||||
<!--
|
||||
This xbean configuration file supports all the standard Spring XML
|
||||
configuration options such as the following bean definitions.
|
||||
|
|
|
@ -41,32 +41,6 @@
|
|||
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="dynamic-broker1" dataDirectory="${activemq.base}/data">
|
||||
|
||||
<!-- First let's configure connectors -->
|
||||
|
||||
<!--
|
||||
Configure network connector to use multicast protocol
|
||||
For more information, see
|
||||
|
||||
http://activemq.apache.org/multicast-transport-reference.html
|
||||
-->
|
||||
<networkConnectors>
|
||||
<networkConnector uri="multicast://default"
|
||||
dynamicOnly="true"
|
||||
networkTTL="3"
|
||||
prefetchSize="1"
|
||||
decreaseNetworkConsumerPriority="true" />
|
||||
</networkConnectors>
|
||||
|
||||
<!--
|
||||
The transport connectors ActiveMQ will listen to
|
||||
Configure discovery URI to use multicast protocol
|
||||
-->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616" discoveryUri="multicast://default" />
|
||||
</transportConnectors>
|
||||
|
||||
<!-- Now configure the rest of the desired broker behavior -->
|
||||
|
||||
<!-- Destination specific policies using destination names or wildcards -->
|
||||
<destinationPolicy>
|
||||
<policyMap>
|
||||
|
@ -87,6 +61,20 @@
|
|||
<managementContext createConnector="true"/>
|
||||
</managementContext>
|
||||
|
||||
<!--
|
||||
Configure network connector to use multicast protocol
|
||||
For more information, see
|
||||
|
||||
http://activemq.apache.org/multicast-transport-reference.html
|
||||
-->
|
||||
<networkConnectors>
|
||||
<networkConnector uri="multicast://default"
|
||||
dynamicOnly="true"
|
||||
networkTTL="3"
|
||||
prefetchSize="1"
|
||||
decreaseNetworkConsumerPriority="true" />
|
||||
</networkConnectors>
|
||||
|
||||
<persistenceAdapter>
|
||||
<kahaDB directory="${activemq.base}/data/dynamic-broker1/kahadb"/>
|
||||
</persistenceAdapter>
|
||||
|
@ -106,6 +94,15 @@
|
|||
</systemUsage>
|
||||
</systemUsage>
|
||||
|
||||
<!--
|
||||
The transport connectors ActiveMQ will listen to
|
||||
Configure discovery URI to use multicast protocol
|
||||
-->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616" discoveryUri="multicast://default" />
|
||||
</transportConnectors>
|
||||
|
||||
|
||||
</broker>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -42,32 +42,6 @@
|
|||
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="dynamic-broker2" dataDirectory="${activemq.base}/data">
|
||||
|
||||
<!-- First let's configure connectors -->
|
||||
|
||||
<!--
|
||||
Configure network connector to use multicast protocol
|
||||
For more information, see
|
||||
|
||||
http://activemq.apache.org/multicast-transport-reference.html
|
||||
-->
|
||||
<networkConnectors>
|
||||
<networkConnector uri="multicast://default"
|
||||
dynamicOnly="true"
|
||||
networkTTL="3"
|
||||
prefetchSize="1"
|
||||
decreaseNetworkConsumerPriority="true" />
|
||||
</networkConnectors>
|
||||
|
||||
<!--
|
||||
The transport connectors ActiveMQ will listen to
|
||||
Configure discovery URI to use multicast protocol
|
||||
-->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61618" discoveryUri="multicast://default" />
|
||||
</transportConnectors>
|
||||
|
||||
<!-- Now configure the rest of the desired broker behavior -->
|
||||
|
||||
<!-- Destination specific policies using destination names or wildcards -->
|
||||
<destinationPolicy>
|
||||
<policyMap>
|
||||
|
@ -87,6 +61,21 @@
|
|||
<managementContext>
|
||||
<managementContext createConnector="true" connectorPort="1100"/>
|
||||
</managementContext>
|
||||
|
||||
<!--
|
||||
Configure network connector to use multicast protocol
|
||||
For more information, see
|
||||
|
||||
http://activemq.apache.org/multicast-transport-reference.html
|
||||
-->
|
||||
<networkConnectors>
|
||||
<networkConnector uri="multicast://default"
|
||||
dynamicOnly="true"
|
||||
networkTTL="3"
|
||||
prefetchSize="1"
|
||||
decreaseNetworkConsumerPriority="true" />
|
||||
</networkConnectors>
|
||||
|
||||
|
||||
<persistenceAdapter>
|
||||
<kahaDB directory="${activemq.base}/data/dynamic-broker2/kahadb" />
|
||||
|
@ -107,6 +96,14 @@
|
|||
</systemUsage>
|
||||
</systemUsage>
|
||||
|
||||
<!--
|
||||
The transport connectors ActiveMQ will listen to
|
||||
Configure discovery URI to use multicast protocol
|
||||
-->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61618" discoveryUri="multicast://default" />
|
||||
</transportConnectors>
|
||||
|
||||
</broker>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -28,7 +28,11 @@
|
|||
|
||||
e.g. $ bin/activemq xbean:conf/activemq-jdbc.xml
|
||||
-->
|
||||
<beans>
|
||||
<beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
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-2.0.xsd
|
||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||
|
||||
<broker useJmx="false" brokerName="jdbcBroker" xmlns="http://activemq.apache.org/schema/core">
|
||||
<persistenceAdapter>
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
</property>
|
||||
</bean>
|
||||
|
||||
<broker useJmx="true" persistent="false" xmlns="http://activemq.apache.org/schema/core">
|
||||
<broker useJmx="true" persistent="false" xmlns="http://activemq.apache.org/schema/core" destroyApplicationContextOnStop="true">
|
||||
|
||||
<plugins>
|
||||
<!-- Configure authentication; Username, passwords and groups -->
|
||||
|
|
|
@ -43,23 +43,6 @@
|
|||
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="static-broker1" dataDirectory="${activemq.base}/data">
|
||||
|
||||
<!-- First let's configure connectors -->
|
||||
|
||||
<!--
|
||||
The store and forward broker networks ActiveMQ will listen to.
|
||||
We'll leave it empty as duplex network will be configured by another broker
|
||||
Take a look at activemq-static_network-broker2.xml for example
|
||||
-->
|
||||
<networkConnectors>
|
||||
</networkConnectors>
|
||||
|
||||
<!-- The transport connectors ActiveMQ will listen to -->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
|
||||
</transportConnectors>
|
||||
|
||||
<!-- Now configure the rest of the desired broker behavior -->
|
||||
|
||||
<!-- Destination specific policies using destination names or wildcards -->
|
||||
<destinationPolicy>
|
||||
<policyMap>
|
||||
|
@ -80,6 +63,14 @@
|
|||
<managementContext createConnector="true"/>
|
||||
</managementContext>
|
||||
|
||||
<!--
|
||||
The store and forward broker networks ActiveMQ will listen to.
|
||||
We'll leave it empty as duplex network will be configured by another broker
|
||||
Take a look at activemq-static_network-broker2.xml for example
|
||||
-->
|
||||
<networkConnectors>
|
||||
</networkConnectors>
|
||||
|
||||
<persistenceAdapter>
|
||||
<kahaDB directory="${activemq.base}/data/static-broker1/kahadb" />
|
||||
</persistenceAdapter>
|
||||
|
@ -99,6 +90,11 @@
|
|||
</systemUsage>
|
||||
</systemUsage>
|
||||
|
||||
<!-- The transport connectors ActiveMQ will listen to -->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
|
||||
</transportConnectors>
|
||||
|
||||
</broker>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -43,23 +43,6 @@
|
|||
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="static-broker1" dataDirectory="${activemq.base}/data">
|
||||
|
||||
<!-- First let's configure connectors -->
|
||||
|
||||
<!--
|
||||
The store and forward broker networks ActiveMQ will listen to
|
||||
Create a duplex connector to the first broker
|
||||
-->
|
||||
<networkConnectors>
|
||||
<networkConnector uri="static:(tcp://localhost:61616)" duplex="true"/>
|
||||
</networkConnectors>
|
||||
|
||||
<!-- The transport connectors ActiveMQ will listen to -->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61618"/>
|
||||
</transportConnectors>
|
||||
|
||||
<!-- Now configure the rest of the desired broker behavior -->
|
||||
|
||||
<!-- Destination specific policies using destination names or wildcards -->
|
||||
<destinationPolicy>
|
||||
<policyMap>
|
||||
|
@ -80,6 +63,14 @@
|
|||
<managementContext createConnector="true" connectorPort="1100"/>
|
||||
</managementContext>
|
||||
|
||||
<!--
|
||||
The store and forward broker networks ActiveMQ will listen to
|
||||
Create a duplex connector to the first broker
|
||||
-->
|
||||
<networkConnectors>
|
||||
<networkConnector uri="static:(tcp://localhost:61616)" duplex="true"/>
|
||||
</networkConnectors>
|
||||
|
||||
<persistenceAdapter>
|
||||
<kahaDB directory="${activemq.base}/data/static-broker2/kahadb" />
|
||||
</persistenceAdapter>
|
||||
|
@ -99,6 +90,11 @@
|
|||
</systemUsage>
|
||||
</systemUsage>
|
||||
|
||||
<!-- The transport connectors ActiveMQ will listen to -->
|
||||
<transportConnectors>
|
||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61618"/>
|
||||
</transportConnectors>
|
||||
|
||||
</broker>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -45,30 +45,7 @@
|
|||
The <broker> element is used to configure the ActiveMQ broker.
|
||||
-->
|
||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.base}/data">
|
||||
|
||||
<!--
|
||||
The managementContext is used to configure how ActiveMQ is exposed in
|
||||
JMX. By default, ActiveMQ uses the MBean server that is started by
|
||||
the JVM. For more information, see:
|
||||
|
||||
http://activemq.apache.org/jmx.html
|
||||
-->
|
||||
<managementContext>
|
||||
<managementContext createConnector="false"/>
|
||||
</managementContext>
|
||||
|
||||
<!--
|
||||
Configure message persistence for the broker. The default persistence
|
||||
mechanism is the KahaDB store (identified by the kahaDB tag).
|
||||
For more information, see:
|
||||
|
||||
http://activemq.apache.org/persistence.html
|
||||
-->
|
||||
<persistenceAdapter>
|
||||
<kahaDB directory="${activemq.base}/data/kahadb"/>
|
||||
</persistenceAdapter>
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
For better performances use VM cursor and small memory limit.
|
||||
For more information, see:
|
||||
|
@ -101,7 +78,31 @@
|
|||
</policyEntry>
|
||||
</policyEntries>
|
||||
</policyMap>
|
||||
</destinationPolicy>
|
||||
</destinationPolicy>
|
||||
|
||||
|
||||
<!--
|
||||
The managementContext is used to configure how ActiveMQ is exposed in
|
||||
JMX. By default, ActiveMQ uses the MBean server that is started by
|
||||
the JVM. For more information, see:
|
||||
|
||||
http://activemq.apache.org/jmx.html
|
||||
-->
|
||||
<managementContext>
|
||||
<managementContext createConnector="false"/>
|
||||
</managementContext>
|
||||
|
||||
<!--
|
||||
Configure message persistence for the broker. The default persistence
|
||||
mechanism is the KahaDB store (identified by the kahaDB tag).
|
||||
For more information, see:
|
||||
|
||||
http://activemq.apache.org/persistence.html
|
||||
-->
|
||||
<persistenceAdapter>
|
||||
<kahaDB directory="${activemq.base}/data/kahadb"/>
|
||||
</persistenceAdapter>
|
||||
|
||||
|
||||
<!--
|
||||
The transport connectors expose ActiveMQ over a given protocol to
|
||||
|
|
|
@ -16,29 +16,35 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
|
||||
<beans xmlns:amq="http://activemq.apache.org/schema/core">
|
||||
<beans
|
||||
xmlns="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-2.0.xsd
|
||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||
|
||||
<amq:broker brokerName="journaledMemBroker" start="false" persistent="false" useShutdownHook="false" deleteAllMessagesOnStartup="true" advisorySupport="false">
|
||||
|
||||
<amq:persistenceAdapter>
|
||||
<amq:journalPersistenceAdapter>
|
||||
<amq:journal>
|
||||
<ref bean="myJournalImpl"/>
|
||||
</amq:journal>
|
||||
|
||||
<amq:persistenceAdapter>
|
||||
<amq:memoryPersistenceAdapter createTransactionStore="true"/>
|
||||
</amq:persistenceAdapter>
|
||||
|
||||
<amq:taskRunnerFactory>
|
||||
<bean id="myTaskRunnerFactory" class="org.apache.activemq.thread.TaskRunnerFactory"/>
|
||||
</amq:taskRunnerFactory>
|
||||
</amq:journalPersistenceAdapter>
|
||||
</amq:persistenceAdapter>
|
||||
|
||||
<amq:transportConnectors>
|
||||
<amq:transportConnector uri="tcp://localhost:61616"/>
|
||||
</amq:transportConnectors>
|
||||
|
||||
<amq:persistenceAdapter>
|
||||
<amq:journalPersistenceAdapter>
|
||||
<constructor-arg index="0">
|
||||
<ref bean="myJournalImpl"/>
|
||||
</constructor-arg>
|
||||
|
||||
<constructor-arg index="1">
|
||||
<amq:memoryPersistenceAdapter init-method="createTransactionStore"/>
|
||||
</constructor-arg>
|
||||
|
||||
<constructor-arg index="2">
|
||||
<bean id="myTaskRunnerFactory" class="org.apache.activemq.thread.TaskRunnerFactory"/>
|
||||
</constructor-arg>
|
||||
</amq:journalPersistenceAdapter>
|
||||
</amq:persistenceAdapter>
|
||||
</amq:broker>
|
||||
|
||||
<!-- The journal implementation that will be used -->
|
||||
|
|
|
@ -15,17 +15,25 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
<!-- START SNIPPET: xbean -->
|
||||
<beans>
|
||||
<beans
|
||||
xmlns="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-2.0.xsd
|
||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
|
||||
|
||||
<broker brokerName="broker" persistent="false" useJmx="false" xmlns="http://activemq.apache.org/schema/core">
|
||||
|
||||
<persistenceAdapter>
|
||||
<kahaPersistenceAdapter directory = "${activemq.home}/activemq-data"/>
|
||||
</persistenceAdapter>
|
||||
|
||||
<transportConnectors>
|
||||
<transportConnector uri="tcp://localhost:61616"/>
|
||||
</transportConnectors>
|
||||
|
||||
<persistenceAdapter>
|
||||
<kahaPersistenceAdapter dir = "${activemq.home}/activemq-data"/>
|
||||
</persistenceAdapter>
|
||||
</broker>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -15,8 +15,13 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
<!-- START SNIPPET: xbean -->
|
||||
<beans>
|
||||
|
||||
<beans
|
||||
xmlns="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-2.0.xsd
|
||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||
|
||||
<broker useJmx="false" brokerName="memoryBroker" xmlns="http://activemq.apache.org/schema/core">
|
||||
<persistenceAdapter>
|
||||
<memoryPersistenceAdapter/>
|
||||
|
|
|
@ -15,10 +15,14 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
<!-- START SNIPPET: xbean -->
|
||||
<beans>
|
||||
|
||||
<beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
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-2.0.xsd
|
||||
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
|
||||
|
||||
<broker useJmx="false" brokerName="quickJdbcBroker" xmlns="http://activemq.apache.org/schema/core">
|
||||
<persistenceAdapter>
|
||||
<persistenceFactory>
|
||||
<journaledJDBC journalLogFiles="4"
|
||||
journalLogFileSize="32768"
|
||||
useJournal="true"
|
||||
|
@ -26,7 +30,7 @@
|
|||
dataSource="#derby-ds"
|
||||
dataDirectory="target/quickJdbc-data"/>
|
||||
|
||||
</persistenceAdapter>
|
||||
</persistenceFactory>
|
||||
|
||||
<transportConnectors>
|
||||
<transportConnector name="default" uri="tcp://localhost:61616"/>
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<beans xmlns:amq="http://activemq.apache.org/schema/core">
|
||||
|
||||
<amq:broker brokerName="quickMemBroker" start="false" persistent="false" useShutdownHook="false" deleteAllMessagesOnStartup="true" advisorySupport="false">
|
||||
|
||||
<amq:transportConnectors>
|
||||
<amq:transportConnector uri="tcp://localhost:61616"/>
|
||||
</amq:transportConnectors>
|
||||
|
||||
<amq:persistenceAdapter>
|
||||
<amq:quickJournalPersistenceAdapter>
|
||||
<constructor-arg index="0">
|
||||
<ref bean="myJournalImpl"/>
|
||||
</constructor-arg>
|
||||
|
||||
<constructor-arg index="1">
|
||||
<amq:memoryPersistenceAdapter init-method="createTransactionStore"/>
|
||||
</constructor-arg>
|
||||
|
||||
<constructor-arg index="2">
|
||||
<bean id="myTaskRunnerFactory" class="org.apache.activemq.thread.TaskRunnerFactory"/>
|
||||
</constructor-arg>
|
||||
</amq:quickJournalPersistenceAdapter>
|
||||
</amq:persistenceAdapter>
|
||||
</amq:broker>
|
||||
|
||||
<!-- The journal implementation that will be used -->
|
||||
<bean id="myJournalImpl" class="org.apache.activeio.journal.active.JournalImpl">
|
||||
<constructor-arg index="0">
|
||||
<bean id="myFile" class="java.io.File">
|
||||
<constructor-arg index="0">
|
||||
<value>target/quickMem-data</value>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -1,51 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<beans xmlns:amq="http://activemq.apache.org/schema/core">
|
||||
|
||||
<amq:broker brokerName="rapidBroker" start="false" persistent="true" useShutdownHook="false" deleteAllMessagesOnStartup="true" advisorySupport="false">
|
||||
|
||||
<amq:transportConnectors>
|
||||
<amq:transportConnector uri="tcp://localhost:61616"/>
|
||||
</amq:transportConnectors>
|
||||
|
||||
<amq:persistenceAdapter>
|
||||
<amq:rapidPersistenceAdapter>
|
||||
<constructor-arg index="0">
|
||||
<ref bean="myJournalImpl"/>
|
||||
</constructor-arg>
|
||||
|
||||
<constructor-arg index="1">
|
||||
<bean id="myTaskRunnerFactory" class="org.apache.activemq.thread.TaskRunnerFactory"/>
|
||||
</constructor-arg>
|
||||
</amq:rapidPersistenceAdapter>
|
||||
</amq:persistenceAdapter>
|
||||
</amq:broker>
|
||||
|
||||
<!-- The journal implementation that will be used -->
|
||||
<bean id="myJournalImpl" class="org.apache.activeio.journal.active.JournalImpl">
|
||||
<constructor-arg index="0">
|
||||
<bean id="myFile" class="java.io.File">
|
||||
<constructor-arg index="0">
|
||||
<value>target/rapid-data</value>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnection;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
import org.apache.activemq.transport.stomp.StompConnection;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class BrokerXmlConfigStartTest extends TestCase {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(BrokerXmlConfigStartTest.class);
|
||||
Properties secProps;
|
||||
public void testStartBrokerUsingXmlConfig() throws Exception {
|
||||
doTestStartBrokerUsingXmlConfig("xbean:src/release/conf/activemq.xml");
|
||||
}
|
||||
|
||||
public void testStartBrokerUsingSampleConfig() throws Exception {
|
||||
// resource:copy-resource brings all config files into target/conf
|
||||
File sampleConfDir = new File("target/conf");
|
||||
|
||||
for (File xmlFile : sampleConfDir.listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.isFile() &&
|
||||
pathname.getName().startsWith("activemq-") &&
|
||||
pathname.getName().endsWith("xml");
|
||||
}})) {
|
||||
|
||||
doTestStartBrokerUsingXmlConfig("xbean:" + sampleConfDir.getAbsolutePath() + "/" + xmlFile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void doTestStartBrokerUsingXmlConfig(String configUrl) throws Exception {
|
||||
|
||||
BrokerService broker = null;
|
||||
LOG.info("Broker config: " + configUrl);
|
||||
System.err.println("Broker config: " + configUrl);
|
||||
broker = BrokerFactory.createBroker(configUrl);
|
||||
// alive, now try connect to connect
|
||||
try {
|
||||
for (TransportConnector transport : broker.getTransportConnectors()) {
|
||||
final URI UriToConnectTo = transport.getConnectUri();
|
||||
|
||||
if (UriToConnectTo.getScheme().startsWith("stomp")) {
|
||||
LOG.info("validating alive with connection to: " + UriToConnectTo);
|
||||
StompConnection connection = new StompConnection();
|
||||
connection.open(UriToConnectTo.getHost(), UriToConnectTo.getPort());
|
||||
connection.close();
|
||||
break;
|
||||
} else if (UriToConnectTo.getScheme().startsWith("tcp")) {
|
||||
LOG.info("validating alive with connection to: " + UriToConnectTo);
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(UriToConnectTo);
|
||||
Connection connection = connectionFactory.createConnection(secProps.getProperty("activemq.username"),
|
||||
secProps.getProperty("activemq.password"));
|
||||
connection.start();
|
||||
connection.close();
|
||||
break;
|
||||
} else {
|
||||
LOG.info("not validating connection to: " + UriToConnectTo);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (broker != null) {
|
||||
broker.stop();
|
||||
broker = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty("activemq.base", "target");
|
||||
secProps = new Properties();
|
||||
secProps.load(new FileInputStream(new File("target/conf/credentials.properties")));
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.config;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
public class BrokerXmlConfigTest extends TestCase {
|
||||
private BrokerService broker;
|
||||
|
||||
public void testStartBrokerUsingXmlConfig() throws Exception {
|
||||
Connection connection = null;
|
||||
try {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
|
||||
connection = connectionFactory.createConnection();
|
||||
connection.start();
|
||||
connection.close();
|
||||
connection = null;
|
||||
} catch (Exception e) {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (JMSException e1) {
|
||||
// ignore exception as we're throwing one anyway
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
System.setProperty("activemq.base", "target");
|
||||
// new File("target/data").mkdirs();
|
||||
broker = BrokerFactory.createBroker("xbean:src/release/conf/activemq.xml");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
if (broker != null) {
|
||||
broker.stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.config;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
|
||||
public class ValidateXMLConfigTest {
|
||||
private static final String SCHEMA_LANGUAGE_ATTRIBUTE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
|
||||
private static final String XSD_SCHEMA_LANGUAGE = "http://www.w3.org/2001/XMLSchema";
|
||||
|
||||
|
||||
@Test
|
||||
public void validateDefaultConfig() throws Exception {
|
||||
validateXML("src/release/conf/activemq.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateExampleConfig() throws Exception {
|
||||
// resource:copy-resource brings all config files into target/conf
|
||||
File sampleConfDir = new File("target/conf");
|
||||
|
||||
for (File xmlFile : sampleConfDir.listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.isFile() && pathname.getName().endsWith("xml");
|
||||
}})) {
|
||||
|
||||
validateXML(xmlFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateXML(String fileName) throws Exception {
|
||||
File xmlFile = new File(fileName);
|
||||
validateXML(xmlFile);
|
||||
}
|
||||
|
||||
private void validateXML(File file) throws Exception {
|
||||
getDocumentBuilder(file.getAbsolutePath()).parse(file);
|
||||
}
|
||||
|
||||
private DocumentBuilder getDocumentBuilder(final String fileName) throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setValidating(true);
|
||||
factory.setNamespaceAware(true);
|
||||
factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
|
||||
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
|
||||
builder.setEntityResolver(new EntityResolver() {
|
||||
|
||||
public InputSource resolveEntity(String publicId, String systemId)
|
||||
throws SAXException, IOException {
|
||||
System.err.println("resolve: " + publicId + ", sys: " + systemId);
|
||||
InputSource source = null;
|
||||
if (systemId.endsWith("activemq-core.xsd")) {
|
||||
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("activemq.xsd");
|
||||
source = new InputSource(stream);
|
||||
source.setPublicId(publicId);
|
||||
source.setSystemId(systemId);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
});
|
||||
|
||||
builder.setErrorHandler(new ErrorHandler() {
|
||||
public void error(SAXParseException exception) throws SAXException {
|
||||
fail(fileName + ", " + exception.toString());
|
||||
}
|
||||
public void fatalError(SAXParseException exception)
|
||||
throws SAXException {
|
||||
fail(fileName + ", " + exception.toString());
|
||||
}
|
||||
public void warning(SAXParseException exception)
|
||||
throws SAXException {
|
||||
fail(fileName + ", " + exception.toString());
|
||||
}
|
||||
});
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue