Giter Club home page Giter Club logo

jnrx's Introduction

JNRX

Simple pub sub library that run on Android platform

Goals

  • Replicate rx java

Usage

  • Clone this repo
  • Open your android studio
  • File -> New -> Import Module
  • Choose this project
  • In your app build.gradle add these lines
compile project(":jnrx")

How to create Channel Stream

  • Add these lines in the root all of your activity code
Jnrx.jnrx.createPublicStream(1);

How to subscribe

  • Make sure you have create one or more channel strea,
  • In this example i will guide you by create a class called Subscriber
  • Subscriber class will act as a subscriber
public class Message {

    private String msg;

    public Message(String msg) {
        this.msg = msg;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
import com.labs.jonathan.jnrxs.Jnrx;
import com.labs.jonathan.jnrxs.OnMessage;


public class Subscriber {
    private String classifier;
    public Subscriber(int streamId, int subscriberId, String classifier) {
        this.classifier = classifier;
        try {
            Jnrx.jnrx.addSubscriber(streamId, this, subscriberId);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @OnMessage
    private void onMessage(Message message) {
        System.out.println(message.getMsg());
    }
}
  • Add the lines to register your susbcriber into a channel stream
  • These lines means you create a subscriber into channel stream with id 1, and subscriber with id 10
Subscriber subscriber =  new Subscriber(1, 10, "Subscriber A");

How to Publish

Message message = new Message("publish message");
Jnrx.jnrx.publish(1, message, 10);
  • These lines means you want to publish message to channel stream with id 1 and subscriber with id 10

Contributing

  • Feel free to open PR.

License

MIT Licensed

jnrx's People

Contributors

codepawpaw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.