GithubHelp home page GithubHelp logo

hhy5277 / rsocket-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rsocket/rsocket-java

0.0 2.0 0.0 3.54 MB

Java implementation of RSocket

Home Page: http://rsocket.io

License: Apache License 2.0

Shell 0.12% Java 99.88%

rsocket-java's Introduction

RSocket

Join the chat at https://gitter.im/RSocket/reactivesocket-java

RSocket is a binary protocol for use on byte stream transports such as TCP, WebSockets, and Aeron.

It enables the following symmetric interaction models via async message passing over a single connection:

  • request/response (stream of 1)
  • request/stream (finite stream of many)
  • fire-and-forget (no response)
  • event subscription (infinite stream of many)

Learn more at http://rsocket.io

Build and Binaries

Build Status

Releases are available via Maven Central.

Example:

dependencies {
    implementation 'io.rsocket:rsocket-core:0.11.14'
    implementation 'io.rsocket:rsocket-transport-netty:0.11.14'
//    implementation 'io.rsocket:rsocket-core:0.11.15.BUILD-SNAPSHOT'
//    implementation 'io.rsocket:rsocket-transport-netty:0.11.15.BUILD-SNAPSHOT'
}

Development

Install the google-java-format in Intellij, from Plugins preferences. Enable under Preferences -> Other Settings -> google-java-format Settings

Format automatically with

$./gradlew goJF

Debugging

Frames can be printed out to help debugging. Set the logger io.rsocket.FrameLogger to debug to print the frames.

Requirements

Trivial Client

package io.rsocket.transport.netty;

import io.rsocket.Payload;
import io.rsocket.RSocket;
import io.rsocket.RSocketFactory;
import io.rsocket.transport.netty.client.WebsocketClientTransport;
import io.rsocket.util.DefaultPayload;
import reactor.core.publisher.Flux;

import java.net.URI;

public class ExampleClient {
    public static void main(String[] args) {
        WebsocketClientTransport ws = WebsocketClientTransport.create(URI.create("ws://rsocket-demo.herokuapp.com/ws"));
        RSocket client = RSocketFactory.connect().keepAlive().transport(ws).start().block();

        try {
            Flux<Payload> s = client.requestStream(DefaultPayload.create("peace"));

            s.take(10).doOnNext(p -> System.out.println(p.getDataUtf8())).blockLast();
        } finally {
            client.dispose();
        }
    }
}

Zero Copy

By default to make RSocket easier to use it copies the incoming Payload. Copying the payload comes at cost to performance and latency. If you want to use zero copy you must disable this. To disable copying you must include a payloadDecoder argument in your RSocketFactory. This will let you manage the Payload without copying the data from the underlying transport. You must free the Payload when you are done with them or you will get a memory leak. Used correctly this will reduce latency and increase performance.

Example Server setup

RSocketFactory.receive()
        // Enable Zero Copy
        .payloadDecoder(Frame::retain)
        .acceptor(new PingHandler())
        .transport(TcpServerTransport.create(7878))
        .start()
        .block()
        .onClose()
        .block();

Example Client setup

Mono<RSocket> client =
        RSocketFactory.connect()
            // Enable Zero Copy
            .payloadDecoder(Frame::retain)
            .transport(TcpClientTransport.create(7878))
            .start();

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

LICENSE

Copyright 2015-2018 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

rsocket-java's People

Contributors

aharonha avatar benjchristensen avatar bsideup avatar gitter-badger avatar gregwhitaker avatar jareddellitt avatar junaidkhalid avatar kbahr avatar kojilin avatar krisskross avatar ktoso avatar lehecka avatar lexs avatar mostroverkhov avatar nebhale avatar niteshkant avatar olegdokuka avatar phoad avatar pmackowski avatar qweek avatar rdegnan avatar reactivesocketadmin avatar robertroeser avatar rstoyanchev avatar segabriel avatar simonbasle avatar somasun avatar stevegury avatar tmontgomery avatar yschimke avatar

Watchers

 avatar  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.