Implementation of a client for connecting to a Simple Message Passing Server.
This client follows a NIO implementation.
Declare next dependency:
<dependency>
<groupId>io.github.scruz84</groupId>
<artifactId>smp_client</artifactId>
<version>0.2.0</version>
</dependency>
Example:
final Client client = new ClientBuilder()
.setHost("localhost")
.setPort(1984)
.setUser("sergio")
.setPassword("secret")
.setOnMessageListener(new MyMessageListener())
.build();
client.subscribeTopic("my-topic");
client.unSubscribeTopic("my-topic");
Listener example:
private static class MyMessageListener implements Client.OnMessageListener {
@Override
public void onMessage(String topic, byte[] message) {
System.out.println("Received from topic " + topic + ", content " + new String(message));
}
@Override
public void onError(Throwable t) {
logger.error("Error received!. " + t.getMessage(), t);
}
}