Skip to content
master
Switch branches/tags
Code

Latest commit

* string2Byte 减少拷贝

* 增加ctx

* go fmt

Co-authored-by: dino.ma <mashengjie03@baidu.com>
c005d31

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
rx
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

rsocket-go

logo

GitHub Workflow Status codecov Go Report Card GoDoc License GitHub Release

rsocket-go is an implementation of the RSocket protocol in Go.
IT IS UNDER ACTIVE DEVELOPMENT, APIs are unstable and maybe change at any time until release of v1.0.0.

Features

  • Design For Golang.
  • Thin reactive-streams implementation.
  • Simulate Java SDK API.
  • Fast CLI (Compatible with https://github.com/rsocket/rsocket-cli).
    • Installation: go get github.com/rsocket/rsocket-go/cmd/rsocket-cli
    • Example: rsocket-cli --request -i hello_world --setup setup_me tcp://127.0.0.1:7878

Install

Minimal go version is 1.11.

$ go get -u github.com/rsocket/rsocket-go

Quick Start

Start an echo server

package main

import (
	"context"
	"log"

	"github.com/rsocket/rsocket-go"
	"github.com/rsocket/rsocket-go/payload"
	"github.com/rsocket/rsocket-go/rx/mono"
)

func main() {
	err := rsocket.Receive().
		Acceptor(func(ctx context.Context, setup payload.SetupPayload, sendingSocket rsocket.CloseableRSocket) (rsocket.RSocket, error) {
			// bind responder
			return rsocket.NewAbstractSocket(
				rsocket.RequestResponse(func(msg payload.Payload) mono.Mono {
					return mono.Just(msg)
				}),
			), nil
		}).
		Transport(rsocket.TCPServer().SetAddr(":7878").Build()).
		Serve(context.Background())
	log.Fatalln(err)
}

Connect to echo server

package main

import (
	"context"
	"log"

	"github.com/rsocket/rsocket-go"
	"github.com/rsocket/rsocket-go/payload"
)

func main() {
	// Connect to server
	cli, err := rsocket.Connect().
		SetupPayload(payload.NewString("Hello", "World")).
		Transport(rsocket.TCPClient().SetHostAndPort("127.0.0.1", 7878).Build()).
		Start(context.Background())
	if err != nil {
		panic(err)
	}
	defer cli.Close()
	// Send request
	result, err := cli.RequestResponse(payload.NewString("你好", "世界")).Block(context.Background())
	if err != nil {
		panic(err)
	}
	log.Println("response:", result)
}

NOTICE: more server examples are Here

Advanced

rsocket-go provides TCP/Websocket transport implementations by default. Since v0.6.0, you can use core package to implement your own RSocket transport. I created an example project which show how to implement an unofficial QUIC transport. You can see rsocket-transport-quic if you are interested.

TODO

  • Wiki
  • UT: 90% coverage