Home

Awesome

rpcx-java

Unmaintained: 目前没有资源维护这个项目。欢迎有时间的开发者接手。

example

assume you have started a Go rpcx server:

package main

import (
	"context"
	"flag"

	"github.com/smallnest/rpcx/server"
)

var (
	addr = flag.String("addr", "192.168.31.82:8997", "server address")
)

type Echo int

func (t *Echo) Echo(ctx context.Context, args []byte, reply *[]byte) error {
	*reply = []byte("hello" + string(args))
	return nil
}

func main() {
	flag.Parse()

	s := server.NewServer()
	s.RegisterName("echo", new(Echo), "")
	s.Serve("tcp", *addr)
}

You can run it as:

go run main.go

Then you can write the java client:

    @Test
        public void testSendMsg() throws Exception {
            Message req = new Message("Echo", "Echo");
            req.setVersion((byte) 0);
            req.setMessageType(MessageType.Request);
            req.setHeartbeat(false);
            req.setOneway(false);
            req.setCompressType(CompressType.None);
            req.setSerializeType(SerializeType.SerializeNone);
            req.setSeq(123);
            req.metadata.put("test", "1234");
            req.payload = "world".getBytes("UTF-8");

            NettyClient client = new NettyClient(null);
            Message res = client.call("192.168.31.82:8997", req);
            System.out.println(new String(res.payload));
        }

借鉴项目

feature