Skip to content

scruz84/smp-java-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Message Passing Java Client

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);
    }
}

About

Simple Message Passing Java Client

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages