Added MQTT benchmarking utiliy based on FuseSource MQTT client

This commit is contained in:
2012-08-25 11:40:08 +02:00
parent 61f0e261bf
commit 57137da4bc
5 changed files with 205 additions and 1 deletions
+2 -1
View File
@@ -1,2 +1,3 @@
/target/
/parser/target/
/parser/target/
/benchmarking/target/
+115
View File
@@ -0,0 +1,115 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<relativePath>../pom.xml</relativePath>
<artifactId>moquette-parent</artifactId>
<groupId>org.dna.mqtt</groupId>
<version>0.1</version>
</parent>
<artifactId>moquette-bechmark</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>Moquette - Benchmarking tool</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- <dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.0.4</version>
</dependency>-->
<!-- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.4</version>
</dependency>-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.dna.mqtt</groupId>
<artifactId>moquette-parser</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.fusesource.mqtt-client</groupId>
<artifactId>mqtt-client</artifactId>
<version>1.3</version>
</dependency>
<!-- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
needs extra dependencies: objenesis & hamcrest
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>org/dna/mqtt/moquette/proto/TestUtils.java</exclude>
<exclude>org/dna/mqtt/moquette/proto/TestUtils$*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.dna.mqtt.moquette.server.Server</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>-->
</plugins>
</build>
<!-- <repositories>
<repository>
<id>Fusesource Releases</id>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
</repository>
</repositories>-->
</project>
@@ -0,0 +1,24 @@
package org.dna.mqtt.bechnmark;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
*
* Benchmark tool entry point.
*
* You could set the number of producers and consumers
*
* @author andrea
*/
public class Main {
private static final int PUBLISHER_POOL_SIZE = 2;
public static void main(String[] args) {
ExecutorService pool = Executors.newFixedThreadPool(PUBLISHER_POOL_SIZE);
pool.submit(new Producer("Client1"));
pool.shutdown();
}
}
@@ -0,0 +1,63 @@
package org.dna.mqtt.bechnmark;
import java.net.URISyntaxException;
import java.util.logging.Level;
import org.fusesource.mqtt.client.BlockingConnection;
import org.fusesource.mqtt.client.MQTT;
import org.fusesource.mqtt.client.QoS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class only publish MQTT messages to a define topic with a certain frequency.
*
*
* @author andrea
*/
public class Producer implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(Producer.class);
private String m_clientID;
public Producer(String clientID) {
m_clientID = clientID;
}
public void run() {
MQTT mqtt = new MQTT();
try {
// mqtt.setHost("test.mosquitto.org", 1883);
mqtt.setHost("localhost", 1883);
} catch (URISyntaxException ex) {
LOG.error(null, ex);
return;
}
mqtt.setClientId(m_clientID);
BlockingConnection connection = mqtt.blockingConnection();
try {
connection.connect();
} catch (Exception ex) {
LOG.error("Cant't CONNECT to the server", ex);
return;
}
//TODO loop
try {
LOG.info("Publishing");
connection.publish("/topic", "Hello world MQTT!!".getBytes(), QoS.AT_MOST_ONCE, false);
} catch (Exception ex) {
LOG.error("Cant't PUSBLISH to the server", ex);
return;
}
try {
LOG.info("Disconneting");
connection.disconnect();
LOG.info("Disconnected");
} catch (Exception ex) {
LOG.error("Cant't DISCONNECT to the server", ex);
}
}
}
+1
View File
@@ -13,6 +13,7 @@
<modules>
<module>parser</module>
<module>benchmarking</module>
</modules>
</project>