Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test project for Netty client.
- Loading branch information
1 parent
41db027
commit 2d29bff
Showing
5 changed files
with
150 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0"?> | ||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>root</artifactId> | ||
<groupId>com.albin.mqtt</groupId> | ||
<version>0.1-SNAPSHOT</version> | ||
</parent> | ||
<groupId>com.albin.mqtt</groupId> | ||
<artifactId>netty-test-client</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
<name>netty-test-client</name> | ||
<url>http://maven.apache.org</url> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>2.3.1</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<mainClass>com.albin.NettyMain</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>2.2</version> | ||
<configuration> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<archive> | ||
<manifest> | ||
<mainClass>com.albin.NettyMain</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> <!-- this is used for inheritance merges --> | ||
<phase>package</phase> <!-- bind to the packaging phase --> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.albin.mqtt</groupId> | ||
<artifactId>mqtt-library</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.albin; | ||
|
||
import java.io.IOException; | ||
import java.net.UnknownHostException; | ||
|
||
import com.albin.mqtt.MqttClient; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) throws UnknownHostException, IOException, InterruptedException { | ||
MqttClient client = new MqttClient(); | ||
client.connect("localhost", 1883, "Albin"); | ||
Thread.sleep(3000); | ||
// client.subscribe("$SYS/#"); | ||
Thread.sleep(1000); | ||
Thread.sleep(30000); | ||
client.disconnect(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.albin; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import com.albin.mqtt.NettyClient; | ||
|
||
public class NettyMain { | ||
|
||
private static NettyClient client; | ||
private static String topic; | ||
|
||
public static void main(String[] args) throws InterruptedException, IOException { | ||
client = new NettyClient(args[0]); | ||
client.connect(); | ||
beInteractive(); | ||
client.disconnect(); | ||
} | ||
|
||
private static void beInteractive() throws IOException { | ||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | ||
String line; | ||
do { | ||
line = in.readLine(); | ||
if (line.startsWith("pub")) | ||
publish(line.substring(4)); | ||
if (line.startsWith("sub")) | ||
subscribe(line.substring(4)); | ||
if (line.startsWith("unsub")) | ||
unsubscribe(line.substring(6)); | ||
if (line.startsWith("topic")) { | ||
topic = line.substring(6); | ||
} | ||
} while(!"bye".equals(line)); | ||
|
||
} | ||
|
||
private static void unsubscribe(String topic) { | ||
client.unsubscribe(topic); | ||
} | ||
|
||
private static void subscribe(String topic) { | ||
client.subscribe(topic); | ||
} | ||
|
||
private static void publish(String msg) { | ||
client.publish(topic, msg); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters