Comments (11)
please attach your full code
from rpcx-gateway.
package main
import (
"errors"
"flag"
"fmt"
"log"
"strings"
"time"
gateway "github.com/rpcx-ecosystem/rpcx-gateway"
"github.com/smallnest/rpcx/client"
)
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")
//------------- 改成了我自己的-------
basePath = flag.String("basepath", "/rpcx_test", "basepath for zookeeper, etcd and consul")
failmode = flag.Int("failmode", int(client.Failover), "failMode, Failover in default")
selectMode = flag.Int("selectmode", int(client.RoundRobin), "selectMode, RoundRobin in default")
)
func main() {
flag.Parse()
d, err := createServiceDiscovery(*registry)
if err != nil {
log.Fatal(err)
}
gw := gateway.NewGateway(*addr, gateway.ServerType(*st), d, client.FailMode(*failmode), client.SelectMode(*selectMode), client.DefaultOption)
fmt.Print("--------网关开始接受请求-----")
gw.Serve()
}
func createServiceDiscovery(regAddr string) (client.ServiceDiscovery, error) {
i := strings.Index(regAddr, "://")
if i < 0 {
return nil, errors.New("wrong format registry address. The right fotmat is [registry_type://address]")
}
regType := regAddr[:i]
regAddr = regAddr[i+3:]
switch regType {
case "peer2peer": //peer2peer://127.0.0.1:8972
return client.NewPeer2PeerDiscovery("tcp@"+regAddr, ""), nil
case "multiple":
var pairs []*client.KVPair
pp := strings.Split(regAddr, ",")
for _, v := range pp {
pairs = append(pairs, &client.KVPair{Key: v})
}
return client.NewMultipleServersDiscovery(pairs), nil
case "zookeeper":
return client.NewZookeeperDiscovery(*basePath, "placeholder", []string{regAddr}, nil), nil
case "etcd":
return client.NewEtcdDiscovery(*basePath, "placeholder", []string{regAddr}, nil), nil
case "consul": // -------- 改成了我自己的 ----
return client.NewConsulDiscovery(*basePath, "Login", []string{regAddr}, nil), nil
case "mdns":
client.NewMDNSDiscovery("placeholder", 10*time.Second, 10*time.Second, "")
default:
return nil, fmt.Errorf("wrong registry type %s. only support peer2peer,multiple, zookeeper, etcd, consul and mdns", regType)
}
return nil, errors.New("wrong registry type. only support peer2peer,multiple, zookeeper, etcd, consul and mdns")
}
from rpcx-gateway.
我用 go客户端 访问consul 调用 服务器端是可以的,但node,js 调用gateway -->consul --> rpc服务 则不行
会报错 018/01/06 17:34:44 server.go:307: WARN : rpcx: failed to handle request: rpcx: can't find service
app.get('/test', function (req, res) {
request({
url: "http://localhost:9981/",
method: "POST",
headers: {
'Content-Type': 'application/rpcx',
'X-RPCX-MessageID': '12345678',
'X-RPCX-MesssageType': '0', //设置0作为请求 1--响应
'X-RPCX-SerializeType': '1',
'X-RPCX-ServicePath': '',
'X-RPCX-ServiceMethod': 'Login'
},
body: '{"Name":"node.js", "Psw":"调用网关"}'
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}else{
console.log(error.message)
}
});
});
from rpcx-gateway.
- gateway中
// -------- 改成了我自己的 ----
不要做修改 , placeholder
是个占位符,不要动
from rpcx-gateway.
- client中,使用你正确的servicepath和servicemethod,你设置servicepath为空肯定不正确
'X-RPCX-ServicePath': '',
设置你的servicePath, 比如 Login
, 看例子
from rpcx-gateway.
case "consul":
return client.NewConsulDiscovery(*basePath, "placeholder", []string{regAddr}, nil), nil
---------- 改成这样,一启动就报错的---
/rpcx_test/placeholder2018/01/07 12:58:01 consul_discovery.go:60: INFO : cannot get services of from registry: rpcx_test/placeholder%!(EXTRA *errors.errorString=Key not found in store)
panic: Key not found in store
关于 rpcx-gateway 的配置关键点,能详细说明下吗?针对于我的这个 consul 中的 key,我 客户端和gateway 和 servcie端应该怎么配呢?现在的配置用 rpcx 的client是可以调用的,但换成 gateway 就很多莫名其妙问题,能不能给个QQ号,具体交流下啊,大神
from rpcx-gateway.
我现在就差gateway整个项目就算完成了,现在卡在这一步了
from rpcx-gateway.
看rpcx项目的readme,有qq群
from rpcx-gateway.
那你把placeholder换成你的Login。
首先你得明确你的servicepath和servicemethod是什么,
看起来你的ServierPath是Login
,
ServiceMethod是什么?Login
和 Logout
?
跑一下项目中的example试试
from rpcx-gateway.
兄弟,谢谢,我先加QQ群,一下说不清楚
from rpcx-gateway.
Clone method of consul/etcd/zookeeper registry has an issue. Please pull latest rpcx to test
from rpcx-gateway.
Related Issues (20)
- 请求返回错误x-rpcx-errormessage是乱码 HOT 4
- 客户端提交的数据不能支持json HOT 2
- rpcx-gateway是无状态应用,是如何做到对有状态服务的支持? HOT 2
- rpcx-gateway只能通过代码方式发送http请求? HOT 1
- geteway只有客户端例子,服务端怎么写呢?服务端监听的是8872,但是http请求的是9981端口 HOT 4
- cmd/gateway.go registry参数在不同注册方式上怎么写,能给一个例子吗?目前只看见一个peer2peer HOT 1
- Gateway是否能提供对TCP提供支持? HOT 1
- 如果service端是Gzip压缩后的响应,请求的客服端解析报错gzip: invalid header。然而如果不通过gateway网关方式,直接用客户端,请求服务端,没事儿。 HOT 2
- X-RPCX-Meta添加说明
- 当前版本依赖的rpcx-etcd版本中的etcd版本不存在 HOT 3
- go mod 下载包,老是提示etcd包版本问题 HOT 3
- getway 到 后端rpcx服务,断断续续 HOT 2
- Is there any recommended WebSocket gateway? HOT 1
- 可以在proto协议中指定http路径吗?
- how to compile rpc-gateway
- deadlock if rpcx-service is not registed in consul HOT 2
- add charset=utf-8 in header
- 运行'cmd/gateway.go'报错 HOT 1
- go build error HOT 1
- 网关是把http 转成什么协议进行请求rpc server
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rpcx-gateway.