mirror of https://github.com/apache/activemq.git
Module for performance testing. Temporarily used Tools from activemq-optional.
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@410428 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c834a10a01
commit
b8facc37b4
|
@ -0,0 +1,47 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>activemq-parent</artifactId>
|
||||||
|
<groupId>incubator-activemq</groupId>
|
||||||
|
<version>4.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>activemq-perftest</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>ActiveMQ :: Performance Test</name>
|
||||||
|
<description>Performance Testing Framework for ActiveMQ</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>incubator-activemq</groupId>
|
||||||
|
<artifactId>activemq-core</artifactId>
|
||||||
|
<version>4.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>incubator-activemq</groupId>
|
||||||
|
<artifactId>activemq-console</artifactId>
|
||||||
|
<version>4.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>incubator-activemq</groupId>
|
||||||
|
<artifactId>maven-perf-plugin</artifactId>
|
||||||
|
<version>4.0-SNAPSHOT</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,140 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2005-2006 The Apache Software Foundation
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.apache.activemq.tool;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.JMSException;
|
||||||
|
import javax.jms.Message;
|
||||||
|
import javax.jms.MessageConsumer;
|
||||||
|
import javax.jms.MessageListener;
|
||||||
|
import javax.jms.Session;
|
||||||
|
import javax.jms.TextMessage;
|
||||||
|
import javax.jms.Topic;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple tool for consuming messages
|
||||||
|
*
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
public class ConsumerTool extends ToolSupport implements MessageListener {
|
||||||
|
|
||||||
|
protected int count = 0;
|
||||||
|
protected int dumpCount = 10;
|
||||||
|
protected boolean verbose = true;
|
||||||
|
protected int maxiumMessages = 0;
|
||||||
|
private boolean pauseBeforeShutdown;
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ConsumerTool tool = new ConsumerTool();
|
||||||
|
if (args.length > 0) {
|
||||||
|
tool.url = args[0];
|
||||||
|
}
|
||||||
|
if (args.length > 1) {
|
||||||
|
tool.topic = args[1].equalsIgnoreCase("true");
|
||||||
|
}
|
||||||
|
if (args.length > 2) {
|
||||||
|
tool.subject = args[2];
|
||||||
|
}
|
||||||
|
if (args.length > 3) {
|
||||||
|
tool.durable = args[3].equalsIgnoreCase("true");
|
||||||
|
}
|
||||||
|
if (args.length > 4) {
|
||||||
|
tool.maxiumMessages = Integer.parseInt(args[4]);
|
||||||
|
}
|
||||||
|
tool.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
System.out.println("Connecting to URL: " + url);
|
||||||
|
System.out.println("Consuming " + (topic ? "topic" : "queue") + ": " + subject);
|
||||||
|
System.out.println("Using " + (durable ? "durable" : "non-durable") + " subscription");
|
||||||
|
|
||||||
|
Connection connection = createConnection();
|
||||||
|
Session session = createSession(connection);
|
||||||
|
MessageConsumer consumer = null;
|
||||||
|
if (durable && topic) {
|
||||||
|
consumer = session.createDurableSubscriber((Topic) destination, consumerName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
consumer = session.createConsumer(destination);
|
||||||
|
}
|
||||||
|
if (maxiumMessages <= 0) {
|
||||||
|
consumer.setMessageListener(this);
|
||||||
|
}
|
||||||
|
connection.start();
|
||||||
|
|
||||||
|
if (maxiumMessages > 0) {
|
||||||
|
consumeMessagesAndClose(connection, session, consumer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("Caught: " + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onMessage(Message message) {
|
||||||
|
try {
|
||||||
|
if (message instanceof TextMessage) {
|
||||||
|
TextMessage txtMsg = (TextMessage) message;
|
||||||
|
if (verbose) {
|
||||||
|
|
||||||
|
String msg = txtMsg.getText();
|
||||||
|
if( msg.length() > 50 )
|
||||||
|
msg = msg.substring(0, 50)+"...";
|
||||||
|
|
||||||
|
System.out.println("Received: " + msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (verbose) {
|
||||||
|
System.out.println("Received: " + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (++count % dumpCount == 0) {
|
||||||
|
dumpStats(connection);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
catch (JMSException e) {
|
||||||
|
System.out.println("Caught: " + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void consumeMessagesAndClose(Connection connection, Session session, MessageConsumer consumer) throws JMSException, IOException {
|
||||||
|
System.out.println("We are about to wait until we consume: " + maxiumMessages + " message(s) then we will shutdown");
|
||||||
|
|
||||||
|
for (int i = 0; i < maxiumMessages; i++) {
|
||||||
|
Message message = consumer.receive();
|
||||||
|
onMessage(message);
|
||||||
|
}
|
||||||
|
System.out.println("Closing connection");
|
||||||
|
consumer.close();
|
||||||
|
session.close();
|
||||||
|
connection.close();
|
||||||
|
if (pauseBeforeShutdown) {
|
||||||
|
System.out.println("Press return to shut down");
|
||||||
|
System.in.read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,133 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2005-2006 The Apache Software Foundation
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.apache.activemq.tool;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.DeliveryMode;
|
||||||
|
import javax.jms.JMSException;
|
||||||
|
import javax.jms.MessageProducer;
|
||||||
|
import javax.jms.Session;
|
||||||
|
import javax.jms.TextMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple tool for publishing messages
|
||||||
|
*
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
public class ProducerTool extends ToolSupport {
|
||||||
|
|
||||||
|
protected int messageCount = 10;
|
||||||
|
protected long sleepTime = 0L;
|
||||||
|
protected boolean verbose = true;
|
||||||
|
protected int messageSize = 255;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
runTool(args, new ProducerTool());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void runTool(String[] args, ProducerTool tool) {
|
||||||
|
if (args.length > 0) {
|
||||||
|
tool.url = args[0];
|
||||||
|
}
|
||||||
|
if (args.length > 1) {
|
||||||
|
tool.topic = args[1].equalsIgnoreCase("true");
|
||||||
|
}
|
||||||
|
if (args.length > 2) {
|
||||||
|
tool.subject = args[2];
|
||||||
|
}
|
||||||
|
if (args.length > 3) {
|
||||||
|
tool.durable = args[3].equalsIgnoreCase("true");
|
||||||
|
}
|
||||||
|
if (args.length > 4) {
|
||||||
|
tool.messageCount = Integer.parseInt(args[4]);
|
||||||
|
}
|
||||||
|
if (args.length > 5) {
|
||||||
|
tool.messageSize = Integer.parseInt(args[5]);
|
||||||
|
}
|
||||||
|
tool.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
System.out.println("Connecting to URL: " + url);
|
||||||
|
System.out.println("Publishing a Message with size "+messageSize+" to " + (topic ? "topic" : "queue") + ": " + subject);
|
||||||
|
System.out.println("Using " + (durable ? "durable" : "non-durable") + " publishing");
|
||||||
|
|
||||||
|
Connection connection = createConnection();
|
||||||
|
Session session = createSession(connection);
|
||||||
|
MessageProducer producer = createProducer(session);
|
||||||
|
//connection.start();
|
||||||
|
|
||||||
|
sendLoop(session, producer);
|
||||||
|
|
||||||
|
System.out.println("Done.");
|
||||||
|
close(connection, session);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("Caught: " + e);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MessageProducer createProducer(Session session) throws JMSException {
|
||||||
|
MessageProducer producer = session.createProducer(destination);
|
||||||
|
if (durable) {
|
||||||
|
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
|
||||||
|
}
|
||||||
|
return producer;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendLoop(Session session, MessageProducer producer) throws Exception {
|
||||||
|
|
||||||
|
for (int i = 0; i < messageCount; i++) {
|
||||||
|
|
||||||
|
|
||||||
|
TextMessage message = session.createTextMessage(createMessageText(i));
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
String msg = message.getText();
|
||||||
|
if( msg.length() > 50 )
|
||||||
|
msg = msg.substring(0, 50)+"...";
|
||||||
|
System.out.println("Sending message: " + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
producer.send(message);
|
||||||
|
Thread.sleep(sleepTime);
|
||||||
|
}
|
||||||
|
producer.send(session.createMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param i
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String createMessageText(int index) {
|
||||||
|
StringBuffer buffer = new StringBuffer(messageSize);
|
||||||
|
buffer.append("Message: " + index + " sent at: " + new Date());
|
||||||
|
if( buffer.length() > messageSize ) {
|
||||||
|
return buffer.substring(0, messageSize);
|
||||||
|
}
|
||||||
|
for( int i=buffer.length(); i < messageSize; i++)
|
||||||
|
buffer.append(' ');
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2005-2006 The Apache Software Foundation
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.apache.activemq.tool;
|
||||||
|
|
||||||
|
import org.apache.activemq.ActiveMQConnection;
|
||||||
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
|
import org.apache.activemq.util.IndentPrinter;
|
||||||
|
|
||||||
|
import javax.jms.Connection;
|
||||||
|
import javax.jms.Destination;
|
||||||
|
import javax.jms.JMSException;
|
||||||
|
import javax.jms.Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class useful for implementation inheritence
|
||||||
|
*
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
public class ToolSupport {
|
||||||
|
|
||||||
|
|
||||||
|
protected Destination destination;
|
||||||
|
protected String subject = "TOOL.DEFAULT";
|
||||||
|
protected boolean topic = true;
|
||||||
|
protected String user = ActiveMQConnection.DEFAULT_USER;
|
||||||
|
protected String pwd = ActiveMQConnection.DEFAULT_PASSWORD;
|
||||||
|
protected String url = ActiveMQConnection.DEFAULT_BROKER_URL;
|
||||||
|
protected boolean transacted = false;
|
||||||
|
protected boolean durable = false;
|
||||||
|
protected String clientID = getClass().getName();
|
||||||
|
protected int ackMode = Session.AUTO_ACKNOWLEDGE;
|
||||||
|
protected String consumerName = "James";
|
||||||
|
|
||||||
|
|
||||||
|
protected Session createSession(Connection connection) throws Exception {
|
||||||
|
if (durable) {
|
||||||
|
connection.setClientID(clientID);
|
||||||
|
}
|
||||||
|
Session session = connection.createSession(transacted, ackMode);
|
||||||
|
if (topic) {
|
||||||
|
destination = session.createTopic(subject);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
destination = session.createQueue(subject);
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Connection createConnection() throws JMSException, Exception {
|
||||||
|
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, pwd, url);
|
||||||
|
return connectionFactory.createConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void close(Connection connection, Session session) throws JMSException {
|
||||||
|
// lets dump the stats
|
||||||
|
dumpStats(connection);
|
||||||
|
|
||||||
|
if (session != null) {
|
||||||
|
session.close();
|
||||||
|
}
|
||||||
|
if (connection != null) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void dumpStats(Connection connection) {
|
||||||
|
ActiveMQConnection c = (ActiveMQConnection) connection;
|
||||||
|
c.getConnectionStats().dump(new IndentPrinter());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
<!-- START SNIPPET: xbean -->
|
||||||
|
<beans xmlns="http://activemq.org/config/1.0">
|
||||||
|
|
||||||
|
<broker useJmx="true">
|
||||||
|
|
||||||
|
<!-- 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="target/activemq-data"/>
|
||||||
|
<!-- To use a different datasource, use th 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>
|
||||||
|
<!-- END SNIPPET: xbean -->
|
Loading…
Reference in New Issue