rsocket-go is an implementation of the RSocket protocol in Go.
- Design For Golang.
- Thin reactive-streams implementation.
- Simulate Java SDK API.
- Fast CLI (Compatible with https://github.com/rsocket/rsocket-cli).
- Installation:
go install github.com/rsocket/rsocket-go/cmd/rsocket-cli@latest
- Example:
rsocket-cli --request -i hello_world --setup setup_me tcp://127.0.0.1:7878
- Installation:
Minimal go version is 1.11.
$ go install github.com/rsocket/rsocket-go/cmd/rsocket-cli@latest
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
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.
- Wiki
- UT: 90% coverage