Skip to content

๐Ÿ€ Fast as rat in server room solution to implement NATS solution

License

Notifications You must be signed in to change notification settings

Szczurowsky/RatOverNATS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

RatOverNATS

Fast as rat in server room solution to implement NATS solution

Build with java Who asked

Status:

Branch Tests Code Quality
master CircleCI CodeFactor Grade

Usefull links

Helpful links:

JitPack Repository (Maven or Gradle) ๏ธ

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>
maven { url "https://jitpack.io" }

Dependencies (Maven or Gradle)

Framework Core

<dependency>
    <groupId>com.github.Szczurowsky</groupId>
    <artifactId>RatOverNATS</artifactId>
    <version>1.1.0</version>
</dependency>
implementation 'com.github.Szczurowsky:RatOverNats:1.1.0'

Usage

More complex examples in docs

Connect

With credentials
public class Example {
    
    public Example() {
        RatOverNats ratOverNats = new RatOverNatsBuilder()
                .options(
                        new Options.Builder()
                                .server("nats://localhost:4222")
                                .userInfo("login", "password")
                                .build()
                )
                .build();
    }
    
}
With URI
public class Example {

    public Example() {
        RatOverNats ratOverNats = new RatOverNatsBuilder()
                .uri("nats://localhost:4222")
                .build();
    }
    
}

Registering subscribe handler

Class with instance
public class Example {

    public Example() {
        RatOverNats ratOverNats = new RatOverNatsBuilder()
                .options(
                        new Options.Builder()
                                .server("nats://localhost:4222")
                                .userInfo("login", "password")
                                .build()
                )
                .registerHandler(new TestMessageHandler())
                .build();
    }
    
}
Handler
public class TestMessageHandler extends RatMessageHandler<String> {

    protected TestMessageHandler() {
        super(1, "test");
    }

    @Override
    protected void onReceive(String s, Message message) {
        System.out.println(s);
    }
}

Publish to channel

Class with instance
public class Example {

    public Example() {
        RatOverNats ratOverNats = new RatOverNatsBuilder()
                .options(
                        new Options.Builder()
                                .server("nats://localhost:4222")
                                .userInfo("login", "password")
                                .build()
                )
                .registerHandler(new TestMessageHandler())
                .build();
        ratOverNats.publish("test", new Packet<>("test").setPacketId(1));
    }
    
}