Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

rpcx implementation in Java for server side and client side

License

Notifications You must be signed in to change notification settings

smallnest/rpcx-java

Repository files navigation

rpcx-java

License GoDoc travis codecov

rpcx-java is java implementation of rpcx.

Until now it implements rpcx client with raw protocol.

Why not use rpcx-gateway or direct http invoking?

Yes, you can write a http client to invoke rpcx services via rpcx-gateway, event direct http invoking,

but http protocol is slower than direct TCP communications.

This client can access rpcx services via raw rpcx protocol sync ot async.

installation

  • Maven:
      <dependency>
         <groupId>com.colobu</groupId>
         <artifactId>rpcx</artifactId>
         <version>1.0</version>
      </dependency>
  • glade
compile group: 'com.colobu', name: 'rpcx', version: '1.0'

example

assume you have started a Go rpcx server:

package main

import (
	"context"
	"flag"

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

var (
	addr = flag.String("addr", "localhost:8972", "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:

    public void call() throws Exception {
        //prepare req
        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(12345678);

        req.metadata.put("test", "1234");

        try {
            req.payload = "world".getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            fail("failed to get UTF-8 bytes");
        }


        // create the client
        Client client = new Client();
        client.connect("127.0.0.1", 8972);
        Message res = client.call(req);
        
        // handle response
    }

roadmap

  • 1.x: implement simple rpcx client and bidirectional communication
  • 2.x: support service discovery and service governance
  • 3.x: support develop services in Java

About

rpcx implementation in Java for server side and client side

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.