Giter Club home page Giter Club logo

rpcx-gateway's Introduction

rpcx-gateway

rpcx-gateway is a http gateway for rpcx services.

rpcx is a fast rpc framework. Faster, more features.

You can write rpc http clients in any programming languages such as Java、Python、C#、Node.js、Php、C\C++、Rust and others. See examples

Deployment models

There are two deployment modes: Gateway and Agent

Gateway

You can deploy this as gateway model. Gateway is running at independent servers. Clients sends http requests to gateways, and gateways translate http requests into raw rpcx requests. And then gateways send raw rpcx requests to rpcx services.

when gateways receive rpcx responses, they translates rpcx responses into http responses and return clients.

You can scale gateway easily because it is stateless.

It works like a http load balancer.

Agent

You can also deploy this as agent model. Agents are deploy with clients. They are installed as a daemon application in node of clients. If there are multiple clients in one node, you only need to install one agent.

Clients send http requests to their local agent. The local agent translate http requests into rpcx requests, send rpcx requests to rpcx services, translate rpcx responses into http ressponses.

It works like service mesh.

Protocol

You can send a http request in any programming languages. You must set some extra http headers in requests.

  • X-RPCX-Version: rpcx version
  • X-RPCX-MesssageType: set 0 as request
  • X-RPCX-Heartbeat: is heartbeat request or not, false in default.
  • X-RPCX-Oneway: is one-way request or not, false in default.
  • X-RPCX-SerializeType: 0 as raw bytes, 1 as JSON, 2 as protobuf, 3 as msgpack
  • X-RPCX-MessageID: message ID, uint64 type
  • X-RPCX-ServicePath: service path
  • X-RPCX-ServiceMethod: service method
  • X-RPCX-Meta: extra metadata

For the http response, there are some extra http headers:

  • X-RPCX-Version: rpcx version
  • X-RPCX-MesssageType: 1 as response
  • X-RPCX-Heartbeat: is heartbeat response or not
  • X-RPCX-MessageStatusType: Error or Normal. Error means there is call failure
  • X-RPCX-SerializeType: 0 as raw bytes, 1 as JSON, 2 as protobuf, 3 as msgpack
  • X-RPCX-MessageID: message ID, uint64 type
  • X-RPCX-ServicePath: service path
  • X-RPCX-ServiceMethod: service method
  • X-RPCX-Meta: extra metadata
  • X-RPCX-ErrorMessage: error message if X-RPCX-MessageStatusType is Error

Example

There is a golang http client example:

package main

import (
	"bytes"
	"io/ioutil"
	"log"
	"net/http"

	"github.com/rpcxio/rpcx-gateway"

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

type Args struct {
	A int
	B int
}

type Reply struct {
	C int
}

func main() {
	cc := &codec.MsgpackCodec{}

    // request 
	args := &Args{
		A: 10,
		B: 20,
	}
	data, _ := cc.Encode(args)

	req, err := http.NewRequest("POST", "http://127.0.0.1:9981/", bytes.NewReader(data))
	if err != nil {
		log.Fatal("failed to create request: ", err)
		return
    }
    
    // set extra headers
	h := req.Header
	h.Set(gateway.XSerializeType, "3")
	h.Set(gateway.XServicePath, "Arith")
	h.Set(gateway.XServiceMethod, "Mul")

    // send to gateway
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal("failed to call: ", err)
	}
	defer res.Body.Close()

	// handle http response
	replyData, err := ioutil.ReadAll(res.Body)
	if err != nil {
		log.Fatal("failed to read response: ", err)
	}

    // parse reply
	reply := &Reply{}
	err = cc.Decode(replyData, reply)
	if err != nil {
		log.Fatal("failed to decode reply: ", err)
	}

	log.Printf("%d * %d = %d", args.A, args.B, reply.C)
}

rpcx-gateway's People

Contributors

deagon avatar dependabot[bot] avatar halokid avatar smallnest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpcx-gateway's Issues

how to compile rpc-gateway

Run go get -tags "xxx" github.com/rpcx-ecosystem/rpcx-gateway/cmd, and The following error appears
NewZookeeperDiscoveryTemplate is not found

deadlock if rpcx-service is not registed in consul

followed in gateway.go

g.mu.Lock()
if g.xclients[servicePath] == nil {
	g.xclients[servicePath] = client.NewXClient(servicePath, g.FailMode, g.SelectMode, g.serviceDiscovery.Clone(servicePath), g.Option)
}
xc = g.xclients[servicePath]
g.mu.Unlock()

cannot run g.mu.Unlock() if rpcx-service is not registed in consul, because call panic in consul_disconvery.go
you could add defer before g.mu.Unlock() .

当前版本依赖的rpcx-etcd版本中的etcd版本不存在

依赖
github.com/rpcxio/rpcx-etcd v0.0.0-20201229103411-8317fc934fbb
而rpcx-etcd 这个版本需要go.etcd.io/[email protected]版本,
然后使用了goproxy.io代理后查看etcd所有版本go list -m -json -versions go.etcd.io/etcd@latest,缺少3.4.14版本。
{
"Path": "go.etcd.io/etcd",
"Version": "v3.3.25+incompatible",
"Versions": [
"v0.1.0",
"v0.1.1",
"v0.1.2",
"v0.2.0-rc0",
"v0.2.0-rc1",
"v0.2.0-rc2",
"v0.2.0-rc3",
"v0.2.0-rc4",
"v0.2.0",
"v0.3.0",
"v0.4.0",
"v0.4.1",
"v0.4.2",
"v0.4.3",
"v0.4.4",
"v0.4.5",
"v0.4.6",
"v0.4.7",
"v0.4.8",
"v0.4.9",
"v0.5.0-alpha.0",
"v0.5.0-alpha.1",
"v0.5.0-alpha.2",
"v0.5.0-alpha.3",
"v0.5.0-alpha.4",
"v0.5.0-alpha.5",
"v2.0.0-rc.1+incompatible",
"v2.0.0+incompatible",
"v2.0.1+incompatible",
"v2.0.2+incompatible",
"v2.0.3+incompatible",
"v2.0.4+incompatible",
"v2.0.5+incompatible",
"v2.0.6+incompatible",
"v2.0.7+incompatible",
"v2.0.8+incompatible",
"v2.0.9+incompatible",
"v2.0.10+incompatible",
"v2.0.11+incompatible",
"v2.0.12+incompatible",
"v2.0.13+incompatible",
"v2.1.0-alpha.0+incompatible",
"v2.1.0-alpha.1+incompatible",
"v2.1.0-rc.0+incompatible",
"v2.1.0+incompatible",
"v2.1.1+incompatible",
"v2.1.2+incompatible",
"v2.1.3+incompatible",
"v2.2.0-alpha.0+incompatible",
"v2.2.0-alpha.1+incompatible",
"v2.2.0-rc.0+incompatible",
"v2.2.0+incompatible",
"v2.2.1+incompatible",
"v2.2.2+incompatible",
"v2.2.3+incompatible",
"v2.2.4+incompatible",
"v2.2.5+incompatible",
"v2.3.0-alpha.0+incompatible",
"v2.3.0-alpha.1+incompatible",
"v2.3.0+incompatible",
"v2.3.1+incompatible",
"v2.3.2+incompatible",
"v2.3.3+incompatible",
"v2.3.4+incompatible",
"v2.3.5+incompatible",
"v2.3.6+incompatible",
"v2.3.7+incompatible",
"v2.3.8+incompatible",
"v3.0.0-beta.0+incompatible",
"v3.0.0+incompatible",
"v3.0.1+incompatible",
"v3.0.2+incompatible",
"v3.0.3+incompatible",
"v3.0.4+incompatible",
"v3.0.5+incompatible",
"v3.0.6+incompatible",
"v3.0.7+incompatible",
"v3.0.8+incompatible",
"v3.0.9+incompatible",
"v3.0.10+incompatible",
"v3.0.11+incompatible",
"v3.0.12+incompatible",
"v3.0.13+incompatible",
"v3.0.14+incompatible",
"v3.0.15+incompatible",
"v3.0.16+incompatible",
"v3.0.17+incompatible",
"v3.1.0-alpha.0+incompatible",
"v3.1.0-alpha.1+incompatible",
"v3.1.0-rc.0+incompatible",
"v3.1.0-rc.1+incompatible",
"v3.1.0+incompatible",
"v3.1.1+incompatible",
"v3.1.2+incompatible",
"v3.1.3+incompatible",
"v3.1.4+incompatible",
"v3.1.5+incompatible",
"v3.1.6+incompatible",
"v3.1.7+incompatible",
"v3.1.8+incompatible",
"v3.1.9+incompatible",
"v3.1.10+incompatible",
"v3.1.11+incompatible",
"v3.1.12+incompatible",
"v3.1.13+incompatible",
"v3.1.14+incompatible",
"v3.1.15+incompatible",
"v3.1.16+incompatible",
"v3.1.17+incompatible",
"v3.1.18+incompatible",
"v3.1.19+incompatible",
"v3.1.20+incompatible",
"v3.2.0-rc.0+incompatible",
"v3.2.0-rc.1+incompatible",
"v3.2.0+incompatible",
"v3.2.1+incompatible",
"v3.2.2+incompatible",
"v3.2.3+incompatible",
"v3.2.4+incompatible",
"v3.2.5+incompatible",
"v3.2.6+incompatible",
"v3.2.7+incompatible",
"v3.2.8+incompatible",
"v3.2.9+incompatible",
"v3.2.10+incompatible",
"v3.2.11+incompatible",
"v3.2.12+incompatible",
"v3.2.13+incompatible",
"v3.2.14+incompatible",
"v3.2.15+incompatible",
"v3.2.16+incompatible",
"v3.2.17+incompatible",
"v3.2.18+incompatible",
"v3.2.19+incompatible",
"v3.2.20+incompatible",
"v3.2.21+incompatible",
"v3.2.22+incompatible",
"v3.2.23+incompatible",
"v3.2.24+incompatible",
"v3.2.25+incompatible",
"v3.2.26+incompatible",
"v3.2.27+incompatible",
"v3.2.28+incompatible",
"v3.2.29+incompatible",
"v3.2.30+incompatible",
"v3.2.31+incompatible",
"v3.3.0-rc.0+incompatible",
"v3.3.0-rc.1+incompatible",
"v3.3.0-rc.2+incompatible",
"v3.3.0-rc.3+incompatible",
"v3.3.0-rc.4+incompatible",
"v3.3.0+incompatible",
"v3.3.1+incompatible",
"v3.3.2+incompatible",
"v3.3.3+incompatible",
"v3.3.4+incompatible",
"v3.3.5+incompatible",
"v3.3.6+incompatible",
"v3.3.7+incompatible",
"v3.3.8+incompatible",
"v3.3.9+incompatible",
"v3.3.10+incompatible",
"v3.3.11+incompatible",
"v3.3.12+incompatible",
"v3.3.13+incompatible",
"v3.3.15+incompatible",
"v3.3.16+incompatible",
"v3.3.17+incompatible",
"v3.3.18+incompatible",
"v3.3.19+incompatible",
"v3.3.20+incompatible",
"v3.3.21+incompatible",
"v3.3.22+incompatible",
"v3.3.24+incompatible",
"v3.3.25+incompatible"
],
"Time": "2020-08-24T19:33:27Z",
"GoMod": "C:\GoPath\pkg\mod\cache\download\go.etcd.io\etcd\@v\v3.3.25+incompatible.mod"
}

getway 到 后端rpcx服务,断断续续

请求同一个rpcx服务,第一下好的,第二下就会报错,一直循环
报错信息:
failed to dial server: dial tcp: address /rpc/xxxx: missing port in address

采用 etcd v3,单etcd节点,
后端rpcx服务提示:client has closed this connection

可以在proto协议中指定http路径吗?

类似grpc-gateway,在定义method时指定http路径,请求时不需要通过header设置service/method,直接请求对应的URL path即可。这样感觉更方便些

rpc Echo(StringMessage) returns (StringMessage) {
  option (google.api.http) = {
    post: "/v1/example/echo"
    body: "*"
  };
}

运行'cmd/gateway.go'报错

运行 cmd/gateway.go 后报错如下:
./gateway.go:56:10: undefined: client.NewZookeeperDiscoveryTemplate
./gateway.go:58:10: undefined: client.NewEtcdDiscoveryTemplate
./gateway.go:60:10: undefined: client.NewConsulDiscoveryTemplate

X-RPCX-Meta添加说明

比如认证 auth的key是__AUTH,写法是 k1=v1&k2=v2等

'X-RPCX-Meta': [
            "__AUTH=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTA0MzI3MTYsImlzcyI6ImhqeC1zZXJ2aWNlcyJ9.0d6qHC0Q1DJr_H58tiHkH0a6wpM4fH8mfBdFI-A1zYY"
]

Is there any recommended WebSocket gateway?

This repo is a http gateway, I want to know is there any recommended WebSocket/TCP gateway?

I have a client which connect to server with WebSocket. And on the server side, I want to spilt the complicated logic into several service with RPC. So I need an WebSocket gateway.

go build error

我下载后直接go build 出现以下错误,有一些方法没有定义?请问是我用错了吗?能指导一下吗?
image

register bug

var (
addr = flag.String("addr", ":9981", "http server address")
st = flag.String("st", "http1", "server type: http1 or h2c")
//registry = flag.String("registry", "peer2peer://127.0.0.1:8972", "registry address")
registry = flag.String("registry", "consul://localhost:8500", "registry address")
--------- i use consul ------
......
case "consul": //regAddr is localhost:8500
return client.NewConsulDiscovery(*basePath, "placeholder", []string{regAddr}, nil), nil

compli error:

2018/01/06 12:20:06 consul_discovery.go:59: INFO : cannot get services of from registry: rpcx/placeholder%!(EXTRA *errors.errorString=Key not found in store)
panic: Key not found in store

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.