mirror of https://github.com/apache/activemq.git
added an example of running an embedded broker in Java code
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@366477 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6285f96b15
commit
be19f9aabd
|
@ -16,154 +16,163 @@
|
|||
-->
|
||||
<project name="Inbox" default="help" basedir=".">
|
||||
|
||||
<property name="class.dir" value="target/classes"/>
|
||||
<property name="class.dir" value="target/classes" />
|
||||
|
||||
<!-- example program defaults -->
|
||||
<property name="url" value="tcp://localhost:61616"/>
|
||||
<property name="topic" value="false"/>
|
||||
<property name="subject" value="TEST.FOO"/>
|
||||
<property name="durable" value="false"/>
|
||||
<property name="max" value="10"/>
|
||||
<property name="messageSize" value="1000"/>
|
||||
<property name="clientId" value="consumer1"/>
|
||||
<property name="producerClientId" value="null"/>
|
||||
<property name="timeToLive" value="0"/>
|
||||
<property name="sleepTime" value="0"/>
|
||||
<property name="transacted" value="false"/>
|
||||
<!-- example program defaults -->
|
||||
<property name="url" value="tcp://localhost:61616" />
|
||||
<property name="topic" value="false" />
|
||||
<property name="subject" value="TEST.FOO" />
|
||||
<property name="durable" value="false" />
|
||||
<property name="max" value="10" />
|
||||
<property name="messageSize" value="1000" />
|
||||
<property name="clientId" value="consumer1" />
|
||||
<property name="producerClientId" value="null" />
|
||||
<property name="timeToLive" value="0" />
|
||||
<property name="sleepTime" value="0" />
|
||||
<property name="transacted" value="false" />
|
||||
|
||||
<!-- for WAR -->
|
||||
<property name="app.name" value="activemq-web"/>
|
||||
<property name="app.base.dir" location="target/${app.name}"/>
|
||||
<property name="app.webinf.dir" value="${app.base.dir}/WEB-INF"/>
|
||||
<property name="app.classes.dir" value="${app.webinf.dir}/classes"/>
|
||||
<property name="app.lib.dir" value="${app.webinf.dir}/lib"/>
|
||||
<property name="app.src.dir" value="src"/>
|
||||
<property name="app.conf.dir" value="conf"/>
|
||||
<property name="app.dist.dir" value="target"/>
|
||||
<!-- for WAR -->
|
||||
<property name="app.name" value="activemq-web" />
|
||||
<property name="app.base.dir" location="target/${app.name}" />
|
||||
<property name="app.webinf.dir" value="${app.base.dir}/WEB-INF" />
|
||||
<property name="app.classes.dir" value="${app.webinf.dir}/classes" />
|
||||
<property name="app.lib.dir" value="${app.webinf.dir}/lib" />
|
||||
<property name="app.src.dir" value="src" />
|
||||
<property name="app.conf.dir" value="conf" />
|
||||
<property name="app.dist.dir" value="target" />
|
||||
|
||||
|
||||
<target name="help">
|
||||
<echo>
|
||||
<target name="help">
|
||||
<echo>
|
||||
This script requires Ant 1.6 or higher
|
||||
|
||||
usage:
|
||||
ant -help display ant help screen
|
||||
ant help display this message
|
||||
ant clean delete the built directory
|
||||
ant -help display ant help screen
|
||||
ant help display this message
|
||||
ant clean delete the built directory
|
||||
|
||||
ant consumer creates a consumer which waits until a specific number of messages have been received
|
||||
ant producer creates a producer publishing a number of messages
|
||||
ant consumer creates a consumer which waits until a specific number of messages have been received
|
||||
ant producer creates a producer publishing a number of messages
|
||||
ant embedBroker runs an embedded broker inside Java code
|
||||
|
||||
ant war creates a WAR deployment unit of the ActiveMQ Broker
|
||||
ant war creates a WAR deployment unit of the ActiveMQ Broker
|
||||
</echo>
|
||||
</target>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="target" quiet="true"/>
|
||||
<delete dir="${class.dir}" quiet="true"/>
|
||||
</target>
|
||||
<target name="clean">
|
||||
<delete dir="target" quiet="true" />
|
||||
<delete dir="${class.dir}" quiet="true" />
|
||||
</target>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${class.dir}"/>
|
||||
<mkdir dir="src/ddl"/>
|
||||
<target name="init">
|
||||
<mkdir dir="${class.dir}" />
|
||||
<mkdir dir="src/ddl" />
|
||||
|
||||
<path id="javac.classpath">
|
||||
<pathelement path="${class.dir}"/>
|
||||
<pathelement path="../conf"/>
|
||||
<fileset dir="../lib">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
</target>
|
||||
<path id="javac.classpath">
|
||||
<pathelement path="${class.dir}" />
|
||||
<pathelement path="../conf" />
|
||||
<fileset dir="../lib">
|
||||
<include name="**/*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="compile" depends="init" description="Compile all Java">
|
||||
<javac srcdir="src" destdir="${class.dir}">
|
||||
<classpath refid="javac.classpath"/>
|
||||
</javac>
|
||||
<copy todir="${class.dir}">
|
||||
<fileset dir="src">
|
||||
<include name="**/*.properties"/>
|
||||
<include name="**/*.xml"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="compile" depends="init" description="Compile all Java">
|
||||
<javac srcdir="src" destdir="${class.dir}">
|
||||
<classpath refid="javac.classpath" />
|
||||
</javac>
|
||||
<copy todir="${class.dir}">
|
||||
<fileset dir="src">
|
||||
<include name="**/*.properties" />
|
||||
<include name="**/*.xml" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="war" depends="compile" description="Create the activemq broker war file.">
|
||||
<!--Copy the required jar files-->
|
||||
<copy todir="${app.lib.dir}">
|
||||
<fileset dir="../lib">
|
||||
<include name="*.jar"/>
|
||||
<exclude name="servlet.jar"/>
|
||||
</fileset>
|
||||
<target name="war" depends="compile" description="Create the activemq broker war file.">
|
||||
<!--Copy the required jar files-->
|
||||
<copy todir="${app.lib.dir}">
|
||||
<fileset dir="../lib">
|
||||
<include name="*.jar" />
|
||||
<exclude name="servlet.jar" />
|
||||
</fileset>
|
||||
|
||||
<fileset dir="../lib/optional">
|
||||
<include name="activemq-web*.jar"/>
|
||||
<include name="activemq-container*.jar"/>
|
||||
<include name="commons-bean*.jar"/>
|
||||
<fileset dir="../lib/optional">
|
||||
<include name="activemq-web*.jar" />
|
||||
<include name="activemq-container*.jar" />
|
||||
<include name="commons-bean*.jar" />
|
||||
|
||||
<!-- include Apache Derby for persistence -->
|
||||
<include name="derby*.jar"/>
|
||||
<!-- include Apache Derby for persistence -->
|
||||
<include name="derby*.jar" />
|
||||
|
||||
<!-- include database pooling just in case -->
|
||||
<include name="commons-pool*.jar"/>
|
||||
<include name="commons-db*.jar"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<!--Copy the configuration file-->
|
||||
<copy todir="${app.webinf.dir}">
|
||||
<fileset dir="${app.conf.dir}">
|
||||
<!--Web application configuration file-->
|
||||
<include name="web.xml"/>
|
||||
<!--ActiveMQ configuration file-->
|
||||
<include name="activemq.xml"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${app.classes.dir}">
|
||||
<fileset dir="${app.conf.dir}">
|
||||
<!--Log4j configuration file-->
|
||||
<include name="log4j.properties"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<!-- Create the war file -->
|
||||
<jar jarfile="${app.dist.dir}/${app.name}.war"
|
||||
basedir="${app.base.dir}"/>
|
||||
</target>
|
||||
<!-- include database pooling just in case -->
|
||||
<include name="commons-pool*.jar" />
|
||||
<include name="commons-db*.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<!--Copy the configuration file-->
|
||||
<copy todir="${app.webinf.dir}">
|
||||
<fileset dir="${app.conf.dir}">
|
||||
<!--Web application configuration file-->
|
||||
<include name="web.xml" />
|
||||
<!--ActiveMQ configuration file-->
|
||||
<include name="activemq.xml" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${app.classes.dir}">
|
||||
<fileset dir="${app.conf.dir}">
|
||||
<!--Log4j configuration file-->
|
||||
<include name="log4j.properties" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<!-- Create the war file -->
|
||||
<jar jarfile="${app.dist.dir}/${app.name}.war" basedir="${app.base.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="consumer" depends="compile" description="Runs a simple consumer">
|
||||
<target name="consumer" depends="compile" description="Runs a simple consumer">
|
||||
|
||||
<echo>Running consumer against server at $$url = ${url} for subject $$subject = ${subject}</echo>
|
||||
<java classname="ConsumerTool" fork="yes" maxmemory="100M">
|
||||
<classpath refid="javac.classpath"/>
|
||||
<jvmarg value="-server"/>
|
||||
<arg value="${url}"/>
|
||||
<arg value="${topic}"/>
|
||||
<arg value="${subject}"/>
|
||||
<arg value="${durable}"/>
|
||||
<arg value="${max}"/>
|
||||
<arg value="${clientId}"/>
|
||||
<arg value="${transacted}"/>
|
||||
<arg value="${sleepTime}"/>
|
||||
</java>
|
||||
</target>
|
||||
<echo>Running consumer against server at $$url = ${url} for subject $$subject = ${subject}</echo>
|
||||
<java classname="ConsumerTool" fork="yes" maxmemory="100M">
|
||||
<classpath refid="javac.classpath" />
|
||||
<jvmarg value="-server" />
|
||||
<arg value="${url}" />
|
||||
<arg value="${topic}" />
|
||||
<arg value="${subject}" />
|
||||
<arg value="${durable}" />
|
||||
<arg value="${max}" />
|
||||
<arg value="${clientId}" />
|
||||
<arg value="${transacted}" />
|
||||
<arg value="${sleepTime}" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="producer" depends="compile" description="Runs a simple producer">
|
||||
<target name="producer" depends="compile" description="Runs a simple producer">
|
||||
|
||||
<echo>Running producer against server at $$url = ${url} for subject $$subject = ${subject}</echo>
|
||||
<java classname="ProducerTool" fork="yes" maxmemory="100M">
|
||||
<classpath refid="javac.classpath"/>
|
||||
<jvmarg value="-server"/>
|
||||
<arg value="${url}"/>
|
||||
<arg value="${topic}"/>
|
||||
<arg value="${subject}"/>
|
||||
<arg value="${durable}"/>
|
||||
<arg value="${max}"/>
|
||||
<arg value="${messageSize}"/>
|
||||
<arg value="${producerClientId}"/>
|
||||
<arg value="${timeToLive}"/>
|
||||
<arg value="${sleepTime}"/>
|
||||
<arg value="${transacted}"/>
|
||||
</java>
|
||||
</target>
|
||||
<echo>Running producer against server at $$url = ${url} for subject $$subject = ${subject}</echo>
|
||||
<java classname="ProducerTool" fork="yes" maxmemory="100M">
|
||||
<classpath refid="javac.classpath" />
|
||||
<jvmarg value="-server" />
|
||||
<arg value="${url}" />
|
||||
<arg value="${topic}" />
|
||||
<arg value="${subject}" />
|
||||
<arg value="${durable}" />
|
||||
<arg value="${max}" />
|
||||
<arg value="${messageSize}" />
|
||||
<arg value="${producerClientId}" />
|
||||
<arg value="${timeToLive}" />
|
||||
<arg value="${sleepTime}" />
|
||||
<arg value="${transacted}" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="embedBroker" depends="compile" description="Runs a simple producer">
|
||||
|
||||
<echo>Running an embedded broker example</echo>
|
||||
<java classname="EmbeddedBroker" fork="yes" maxmemory="100M">
|
||||
<classpath refid="javac.classpath" />
|
||||
<jvmarg value="-server" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import org.apache.activemq.broker.BrokerService;
|
||||
|
||||
/**
|
||||
*
|
||||
* Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
**/
|
||||
|
||||
/**
|
||||
* This example demonstrates how to run an embedded broker inside your Java code
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class EmbeddedBroker {
|
||||
public static void main(String[] args) throws Exception {
|
||||
BrokerService broker = new BrokerService();
|
||||
broker.setUseJmx(true);
|
||||
broker.addConnector("tcp://localhost:61616");
|
||||
broker.start();
|
||||
|
||||
// now lets wait forever to avoid the JVM terminating immediately
|
||||
Object lock = new Object();
|
||||
synchronized (lock) {
|
||||
lock.wait();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue