alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

ActiveMQ example source code file (build.xml)

This example ActiveMQ source code file (build.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - ActiveMQ tags/keywords

appender, appender, compile, copy, copy, create, jms, log4j, log4j, log4jjmsappenderexample, runs, runs, stomp, stompexample

The ActiveMQ build.xml source code

<?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.
-->
<project name="Inbox" default="help" basedir=".">

	<property name="class.dir" value="target/classes" />
	<property name="activemq.home" value=".." />

	<!-- 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="2000" />
	<property name="parallelThreads" value="1" />
	<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" />
	<property name="reply-subject" value="" />
	<property name="verbose" value="true"/>
	<property name="ack-mode" value="AUTO_ACKNOWLEDGE"/>
	<property name="receive-time-out" value="0"/>
	<property name="subscribers" value="1"/>
	<property name="batch" value="10"/>
	
	<!-- 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>
            This script requires Ant 1.6 or higher

            NOTE: All options should be specified as system properties 
               on the command line, e.g.:

               ant consumer -Durl=tcp://hostname:1234 -Dtopic=true

                 OR 

               ant producer -Durl=tcp://hostname:61616 -Dmax=1000
      
            Usage:
              ant <ant-task> <options>

            --------------------------------------------------------
            ant consumer <options> - Creates a consumer which waits until a specific number 
                                     of messages have been received
	
            Consumer Options: 
                              url - Used to specify acustom URL for the 
                                    broker, e.g., tcp://hostname:1234
                            topic - A boolean to determine whether to use
                                    topics or queues; the default is false
                          subject - Used to specify a custom destination 
                                    name, e.g. MyDestination
                          durable - A boolean to specify that you want to 
                                    create a durable topic? 
                              max - The maximum number of messages to wait 
                                    for before shutting down 
                         clientId - A string to use as the client id
                       transacted - A boolean to specify that you want to use 
                                    transactions? 
                        sleepTime - The time to sleep between message consumptions
                          verbose - Used to print out more info; the default is
                                    true 
                         ack-mode - The type of message acknowledgement to use; 
                                    see the Javadocs for javax.jms.Session for
                                    more information
                 receive-time-out - An integer to specify the time to wait for
                                    message consumption
                  parallelThreads - The number of parallel threads
                            batch - Batch size for transactions and client acknowledgment (default 10)
				
            --------------------------------------------------------				
            ant producer <options> - Creates a producer publishing a number of messages

            Producer Options: 
                            url - Used to specify acustom URL for the broker,
                                  e.g., tcp://hostname:1234
                          topic - A boolean to determine whether to use topics 
		                        or queues
                        subject - Used to specify a custom destination name, 
                                  e.g. MyDestination
                        durable - A boolean to specify that you want to create 
                                  a durable topic subscriber? 
                           max - The maximum number of messages to wait for 
                                 before shutting down 
                     sleepTime - The time to sleep between message consumptions
                    transacted - A boolean to specify that you want to use 
                                 transactions? 
                       verbose - Used to print out more info; the default is true
                   messageSize - The size of the message in 1-byte characters
               parallelThreads - The number of parallel threads

		   
           --------------------------------------------------------
		
                   ant -help  - Display ant help screen
                    ant help  - Display this message
                   ant clean  - Delete the built directory
             ant embedBroker  - Runs an embedded broker inside Java code
                     ant war  - Creates a WAR deployment unit of the ActiveMQ Broker
    </echo>
	</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" />

		<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="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" />
				<include name="spring*.jar" />
				<include name="xbean*.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>

	<target name="consumer" depends="compile" description="Runs a simple consumer">

		<echo>Running consumer against server at $$url = ${url} for subject $$subject = ${subject}
		<java classname="ConsumerTool" fork="yes" maxmemory="100M">
			<classpath refid="javac.classpath" />
			<jvmarg value="-server" />
		    <sysproperty key="activemq.home" value="${activemq.home}"/>
			<arg value="--url=${url}" />
			<arg value="--topic=${topic}" />
			<arg value="--subject=${subject}" />
			<arg value="--durable=${durable}" />
			<arg value="--maxium-messages=${max}" />
			<arg value="--client-id=${clientId}" />
			<arg value="--parallel-threads=${parallelThreads}" />
			<arg value="--transacted=${transacted}" />
			<arg value="--sleep-time=${sleepTime}" />
			<arg value="--verbose=${verbose}"/>
			<arg value="--ack-mode=${ack-mode}"/>		
			<arg value="--receive-time-out=${receive-time-out}"/>
            <arg value="--batch=${batch}"/>
		</java>
	</target>

	<target name="producer" depends="compile" description="Runs a simple producer">

		<echo>Running producer against server at $$url = ${url} for subject $$subject = ${subject}
		<java classname="ProducerTool" fork="yes" maxmemory="100M">
			<classpath refid="javac.classpath" />
			<jvmarg value="-server" />
		    <sysproperty key="activemq.home" value="${activemq.home}"/>
			<arg value="--url=${url}" />
			<arg value="--topic=${topic}" />
			<arg value="--subject=${subject}" />
			<arg value="--persistent=${durable}" />
			<arg value="--message-count=${max}" />
			<arg value="--message-size=${messageSize}" />
			<arg value="--parallel-threads=${parallelThreads}" />
			<arg value="--time-to-live=${timeToLive}" />
			<arg value="--sleep-time=${sleepTime}" />
			<arg value="--transacted=${transacted}" />
			<arg value="--verbose=${verbose}"/>			
		</java>
	</target>

	<target name="requester" depends="compile" description="Runs a simple requester">

		<echo>Running requester against server at $$url = ${url} for subject $$subject = ${subject}
		<java classname="RequesterTool" fork="yes" maxmemory="100M">
			<classpath refid="javac.classpath" />
			<jvmarg value="-server" />
		    <sysproperty key="activemq.home" value="${activemq.home}"/>
			<arg value="--url=${url}" />
			<arg value="--topic=${topic}" />
			<arg value="--subject=${subject}" />
			<arg value="--persistent=${durable}" />
			<arg value="--message-count=${max}" />
			<arg value="--message-size=${messageSize}" />
			<arg value="--client-id=${producerClientId}" />
			<arg value="--time-to-live=${timeToLive}" />
			<arg value="--sleep-time=${sleepTime}" />
			<arg value="--transacted=${transacted}" />
			<arg value="--reply-subject=${reply-subject}" />
			<arg value="--verbose=${verbose}"/>			
		</java>
	</target>

	<target name="embedBroker" depends="compile" description="Runs a simple producer">

		<echo>Running an embedded broker example
		<java classname="EmbeddedBroker" fork="yes" maxmemory="100M">
			<classpath refid="javac.classpath" />
			<jvmarg value="-server" />
		    <sysproperty key="activemq.home" value="${activemq.home}"/>
		</java>
	</target>
	
	<target name="topic-publisher" depends="compile" description="Runs a publisher">
		<java classname="TopicPublisher" fork="yes" maxmemory="100M">
			<classpath refid="javac.classpath" />
			<jvmarg value="-server" />
			<arg value="--url=${url}" />
			<arg value="--size=${messageSize}" />
			<arg value="--subscribers=${subscribers}" />
			<arg value="--messages=${max}" />
			<arg value="--delay=${sleepTime}" />
			<arg value="--batch=${batch}" />			
		</java>
	</target>	
	
	<target name="topic-listener" depends="compile" description="Runs a listener">
		<java classname="TopicListener" fork="yes" maxmemory="100M">
			<classpath refid="javac.classpath" />
			<jvmarg value="-server" />
			<arg value="--url=${url}" />
		</java>
	</target>	
	
	<target name="stomp" depends="compile" description="Runs a Stomp example">
		<echo>Running a Stomp example
		<java classname="StompExample" fork="yes" maxmemory="100M">
			<classpath refid="javac.classpath" />
			<jvmarg value="-server" />
		</java>
	</target>
	
	<target name="log4j-jms" depends="compile" description="Runs a Log4j JMS Appender example">
		<echo>Running a Log4j JMS Appender example
	    <java classname="Log4jJMSAppenderExample" fork="yes" maxmemory="100M">
	        <classpath refid="javac.classpath" />
	        <jvmarg value="-Dlog4j.configuration=log4j-jms.properties" />
	    </java>
	</target>
	
</project>

Other ActiveMQ examples (source code examples)

Here is a short list of links related to this ActiveMQ build.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.