Skip to content

🌠 Library that extends NATS.io with additional functionalities.

License

Notifications You must be signed in to change notification settings

jedzius/nats-messenger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌠 NATS Messenger (Work In Progress)

Extends pub/sub from NATS.io with lettuce-like (redis library) codecs and abstraction capabilities.


🌠 NATS Messenger :: Usage

Creating new client and connection:

final Options options = Options.builder()
        .server("nats://demo.nats.io:4222")
        .build();
final NatsClient natsClient = NatsMessenger.create(options);
final NatsConnection<String> natsConnection = natsClient.createConnection(new NatsStringCodec());

Subscribing to a channel and publishing messages:

natsConnection.subscribe("test-channel", new NatsTestListener());
/* Or */
natsConnection.subscribe("test-channel", value -> System.out.println(value));
natsConnection.publish("test-channel", "Test message!");
natsConection.publish("test-channel", "Test message with callback!", packet 
        -> System.out.println(packet));

natsConnection.flush(Duration.ZERO);

Example message listener:

class NatsMessageListener implements NatsHandler<String> {

    @Override
    public void onMessageReceive(String value) {
        System.out.println(value);
    }

}

About

🌠 Library that extends NATS.io with additional functionalities.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages