Skip to content

Framework for building Reactive Streaming systems with SPA Websocket clients

License

Notifications You must be signed in to change notification settings

leetoo/reactiveservices

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

"build status"

What is it?

Framework for building Reactive Streaming systems with SPA Websocket clients

Why?

  • Low latency (sub-ms) and high throughput (100,000s/sec)
  • Out-of-the-box Fault tolerance and High Availability with automatic service discovery, split brain recovery and unlimited possibilities of scaling
  • Micro-services oriented
  • Powerful testing framework and DSL
  • Powered by Reactive Streams and Akka
  • Scala and Java (coming soon) API

Sample application built with the framework: "screen1" See https://github.com/intelix/reactfx

1 minute intro

Create a service:

class PriceSourceService extends StatelessServiceActor {
}

Map subject subscription to stream id:

onSubjectMapping {
    case Subject(_, TopicKey(instrument), _) => instrument
}

Add stream lifecycle hooks:

onStreamActive {
  case SimpleStreamId(instrument) => instruments += instrument
}
onStreamPassive {
  case SimpleStreamId(instrument) => instruments -= instrument
}

At any point, publish data into the stream:

instrument !# ("price" -> getPrice)

Define and configure the service:

node.services.price-source = "rs.examples.stocks.PriceSourceService"
price-source.custom-config-param = "some value"

On the client side, subscribe to the stream:

return React.createClass({

    mixins: [RSMixin],

    getInitialState: function () {
        return {data: false};
    },

    subscriptionConfig: function (props) {
        return [
            {
                service: "price-source",
                topic: "AUDUSD",
                ostateKey: "data"
            }
        ];
    },
    
    onTrade: function () {
        var data = this.state.data;
        this.sendSignal("price-source", "trade", {instrument: "AUDUSD", price: data.price});
    },
    
    render: function () {

        var data = this.state.data;

        if (!data) return <div>Loading ...</div>;

        var price = <span>{data.price} <a href="#" onClick={this.onTrade}>Buy</a></span>;

        return <span>{data.price} <a href="#" onClick={this.onTrade}>Buy</a></span>;
    }

});

Receive the trade signal on the service side:

onSignal {
    case (Subject(_, TopicKey("trade"), UserId(uid)), data: String) =>
      // pocess data
      SignalOk()
}
  

Refer to reactiveservices-examples/stocks for a complete runnable sample app.

About

Framework for building Reactive Streaming systems with SPA Websocket clients

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 86.5%
  • JavaScript 12.5%
  • Shell 1.0%