rpcxio / rpcx-examples Goto Github PK
View Code? Open in Web Editor NEWexamples for the latest rpcx
License: Apache License 2.0
examples for the latest rpcx
License: Apache License 2.0
在kcp 所在的demo中,有个WithBlockCrypt()方法,但在 v1.8.24 中没有找到该方法并且最新代码中一直显示该方法undefined 未定义的引入。
是不是可以认为v1.8.24摒弃了rpcx 以kcp协议承载方式rpc server。
请教一下,谢谢!
自己搭建了一个consul服务,
运行rpcx-examples/registry/consul/server没有错误提示。
运行rpcx-examples/registry/consul/client错误提示:
2021/03/28 18:53:12 connection.go:98: WARN : failed to dial server: dial tcp [::1]:8972: connect: connection refused
2021/03/28 18:53:12 connection.go:98: WARN : failed to dial server: dial tcp [::1]:8972: connect: connection refused
2021/03/28 18:53:12 connection.go:98: WARN : failed to dial server: dial tcp [::1]:8972: connect: connection refused
2021/03/28 18:53:12 connection.go:98: WARN : failed to dial server: dial tcp [::1]:8972: connect: connection refused
2021/03/28 18:53:12 connection.go:98: WARN : failed to dial server: dial tcp [::1]:8972: connect: connection refused
2021/03/28 18:53:12 ERROR failed to call: dial tcp [::1]:8972: connect: connection refused
2021/03/28 18:53:12 10 * 20 = 0
目录:github.com/rpcx-ecosystem/rpcx-examples3/registry/inprocess
执行:go run serverandclient.go
结果:2019/02/12 10:58:54 failed to call: service Arith not found
rpcx是否可以传送文件?是否有stream方式?需要自己实现么?
使用示例filetransfer中server端编译失败,显示参数不足,查看源码,应需要四个参数,除示例中使用的参数外,还需要DownloadFileHandler。在file_download示例中,是四个参数,FileTransferHandler用nil替代了。
bidirectional/server/server.go
在这个示例中,这个代码是不是没有用处?
35和36行.这个是不是多余的?
rpcx-examples/bidirectional/server/server.go
Lines 35 to 36 in 9dc5af2
Follow the manual (https://doc.rpcx.io/part1/quickstart.html)
go -get command
The following error will appear, how to solve it
smallnest/rpcx/codec/codec.go:129:15: not enough arguments in call to d.Read
have (thrift.TStruct, []byte)
want (context.Context, thrift.TStruct, []byte)
cmd/main.go:44:8: undefined: serverplugin.EtcdRegisterPlugin
+build etcd
What is the role of +build etcd
?
go.mod 文件中,rpcx 的版本是 1.7.5
如果更新成 1.8.3 版本,发现程序运行结果异常:
以 101basic/ 为例
client.go 执行时
1.8.3 版本
年月日 17:42:31 10 * 20 = 0
如果是 1.7.5 版本
年月日 17:42:31 10 * 20 = 200
求指点
https://github.com/rpcxio/rpcx-examples/tree/master/file_download
在服务器端启动server
在本地电脑上启动client
会报错,无法成功下载文件,如果是在同一个电脑上执行 是没问题的,但是跨机器就不行了。
The demo can run.but key is localhost:8500/v1/kv/rpcx_test(server.go) not localhost:8500/v1/kv/rpcx_test/Arith(client.go)
➜ did git:(master) ✗ kill -HUP 2044
2020/09/29 18:10:06 server.go:175: INFO : server pid:2044
2020/09/29 18:10:31 server.go:764: INFO : restart a new rpcx server: 2063
2020/09/29 18:10:31 server.go:175: INFO : server pid:2063
2020/09/29 18:10:34 server.go:706: INFO : shutdown begin
2020/09/29 18:10:34 server.go:798: INFO : need handle in-processing msg size:0
2020/09/29 18:10:34 gateway.go:78: ERROR: error in gateway Serve: *errors.errorString http: Server closed
panic: http: Server closed
goroutine 19 [running]:
main.main.func1(0xc0002862a0)
/Users/zs/git/projects/did/graceful_restart/server.go:35 +0x85
created by main.main
/Users/zs/git/projects/did/graceful_restart/server.go:32 +0x107
Process finished with exit code 2
go1.15.2 darwin/amd64
MultipleServersDiscovery的update方法没有暴露到ServiceDiscovery接口中
外部client.NewMultipleServersDiscovery(pairs)后无法更新pairs
客户端运行时提示 failed to call: CRYPTO_ERROR: tls: no application protocol
flag.Parse()
share.Trace = true
//d, _ := etcd_client.NewEtcdV3Discovery(*basePath, "Arith", []string{*etcdAddr}, false, nil)
d, _ := client.NewPeer2PeerDiscovery("tcp@"+*addrssss, "")
xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, client.DefaultOption)
defer xclient.Close()
args := &example.Args{
A: 10,
B: 20,
}
for {
reply := &example.Reply{}
err := xclient.Call(context.Background(), "Mul", args, reply)
if err != nil {
log.Printf("failed to call: %v\n", err)
time.Sleep(5 * time.Second)
continue
}
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
time.Sleep(1e9 * time.Second)
}
go get github.com/rpcxio/rpcx-examples
go: downloading github.com/rpcxio/rpcx-examples v1.1.6
go: github.com/rpcxio/[email protected]: verifying module: github.com/rpcxio/[email protected]: checking tree#15389948 against tree#15439110: reading https://goproxy.io/sumdb/sum.golang.org/tile/8/1/234: 404 Not Found
server response: not found
Hi @smallnest,
I was going through the examples as well as the rpcx source code repo but couldn't find an example of MsgPack codec used in a server.
Furthermore, I tried finding one in https://github.com/vmihailenco/msgpack and couldn't find one.
I'd appreciate if you can provide a snippet of how a server using msgpack
would look like.
Thanks!
I was try to run this example:https://github.com/rpcxio/rpcx-examples/tree/master/registry/consul
the server
"register succed":
client
can call server
rpc method.consul
ui Key / Value
area have server
properties.consul
ui Services
area did't show server
name.I expect consul
ui Services
area show register rpcx services name, what should i do? :)
出发点大概是这样的
服务注册后,我们自己做的后台port会去查看注册中心(etcd. zookeeper)上的节点数据, 有时会想将某个机器排除在外,不让其它服务调用它,但我们又不能将此节点删除,做一些事情后又要将其恢复正常
我们现在port后台想做一个开关,直接操作etcd.zookeeper,
能不能在rpcx服务调用前,验证一下那个开关,假如是关闭的话就换成另一个服务去调用
不知我说清楚没,希望大哥空了考虑一下
undefined: serverplugin.ZooKeeperRegisterPlugin
Hi @smallnest!
I've tried building the quic
server, but I get the following error
panic: can not make listener for quic
goroutine 1 [running]:
main.main()
/home/user/go/src/github.com/rpcx-ecosystem/rpcx-examples3/quic/server.go:33 +0x340
Can you give some ideas on why?
发信号
kill -SIGHUP 12068
之后报这个错误
jsonrpc2.go:201: ERROR: error in JSONRPC server: *errors.errorString http: Server closed
虽然可以成功起动一个新进程来监听端口,但是这个错误是正常的吗?
type Server struct {
engine *server.Server
apiRouter *Router
}
func (s *Server) Start() {
s.apiRouter.With(s.engine)
s.engine.Serve("tcp", "localhost:8972")
//s.engine.Serve("reuseport", "localhost:8972")
}
func (s *Server) StartShutdownListener() {
go func(s *Server) {
log.Println("server pid:", os.Getpid())
// channel to receive notifications of SIGTERM and SIGHUP
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGHUP)
// handle signal SIGTERM and SIGHUP
switch <-ch {
case syscall.SIGTERM:
s.engine.RegisterOnShutdown(func(s *server.Server) {
log.Println("graceful shutdown...")
})
s.engine.Shutdown(context.Background())
case syscall.SIGHUP:
s.engine.Restart(context.Background())
s.engine.RegisterOnRestart(func(s *server.Server) {
log.Println("graceful restart...")
})
s.engine.Restart(context.Background())
}
}(s)
}
go版本:
go version go1.20.1 linux/amd64
rpcx : v1.8.24
@smallnest 辛苦看一下 感谢
Exact code as shown in the KCP example -
s := server.NewServer(server.WithBlockCrypt(bc))
This line cannot be compiled as the .WithBlockCrypt is an unresolved reference (kcp is visble)
rpcx-examples/graceful_restart/server.go
Line 33 in e96cba3
https://github.com/rpcxio/rpcx-examples/tree/master/registry/etcdv3
操作这个example报错。
etcd:
etcd Version: 3.4.9
Git SHA: Not provided (use ./build instead of go build)
Go Version: go1.14.3
Go OS/Arch: darwin/amd64
报错1:
etcd的报错
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status: connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status: connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status: connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status: connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status: connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status: connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status: connection error: desc = "transport is closing"
WARNING: 2020/07/14 15:41:25 grpc: Server.processUnaryRPC failed to write status connection error: desc = "transport is closing"
client端端报错:
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
2020/07/14 15:41:25 etcdv3_discovery.go:244: WARN : chan is closed and will rewatch
server报错3:
server连上后,重新关闭,再开启
2020/07/14 15:42:56 etcdv3.go:66: ERROR: cannot create etcd path /rpcx_test: rpc error: code = Canceled desc = grpc: the client connection is closing
2020/07/14 15:42:56 rpc error: code = Canceled desc = grpc: the client connection is closing
exit status 1
怎么弄,大佬
你好,我在学习的过程中,
使用了 go get -u -v -tags "reuseport quic kcp zookeeper etcd consul redis ping utp" github.com/smallnest/rpcx/...
但是在如下的例子中,遇到了编译不了的问题。
go build server.go
# command-line-arguments
./server.go:35:8: undefined: serverplugin.EtcdV3RegisterPlugin
I have installed all the installers correctly and 101basic works fine, but when I try to run kcp server
using the following command.
go run \server.go
I get the following error
server.go:34:31: undefined: server.WithBlockCrypt
How can I solve this problem?
Q as title
我想实现客户也有证书,服务器要验证客户端的证书;我在客户端加了证书 服务端做了验证 客户端访问不到 也没有错误;
下面是我的代码;我这样写有问题吗
客户端:
d, err3 := etcd_client.NewEtcdV3Discovery(*basePath1, *serverName, []string{*etcdAddr1}, false, nil)
if err3 != nil {
log.Panicln("err3:", err3)
}
//conf := &tls.Config{
// InsecureSkipVerify: true,
//}
//加入tls
cert, err := tls.LoadX509KeyPair("../tls/client.crt", "../tls/client.key")
if err != nil {
log.Fatal("err:", err)
}
certPool := x509.NewCertPool()
certBytes, eeee := ioutil.ReadFile("../tls/client.crt")
if eeee != nil {
panic("eeeee")
}
if !certPool.AppendCertsFromPEM(certBytes) {
panic("cc")
}
confls := &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: certPool,
}
option := client.DefaultOption
option.TLSConfig = confls
xclient := client.NewXClient(*serverName, client.Failover, client.RoundRobin, d, option)
defer xclient.Close()
服务端:
cert, err := tls.LoadX509KeyPair("tls/server.crt", "tls/server.key")
if err != nil {
log.Panicln("tls red err:", err)
}
certPool := x509.NewCertPool()
certBytes, err := ioutil.ReadFile("tls/client.crt")
if err != nil {
log.Panicln("errrrrrrr:", err)
}
certPool.AppendCertsFromPEM(certBytes)
//lstconfig := &tls.Config{Certificates: []tls.Certificate{cert}}
lstconfig := &tls.Config{
ClientCAs: certPool,
ClientAuth: tls.RequireAndVerifyClientCert,
Certificates: []tls.Certificate{cert},
}
//实例化user服务的结构体
ctx := svc.NewServicContext(conf)
svr := servic.NewUserServer(ctx)
s := server.NewServer(server.WithTLSConfig(lstconfig))
I use go mod tidy
to download dependency modules,but something error:
go: finding module for package google.golang.org/grpc/naming
go: finding module for package google.golang.org/grpc/examples/helloworld/helloworld
go: found google.golang.org/grpc/examples/helloworld/helloworld in google.golang.org/grpc/examples v0.0.0-20210427222225-24d03d9f7691
go: finding module for package google.golang.org/grpc/naming
github.com/rpcxio/rpcx-examples/101basic/client imports
github.com/smallnest/rpcx/client imports
github.com/docker/libkv/store/etcd imports
github.com/coreos/etcd/client tested by
github.com/coreos/etcd/client.test imports
github.com/coreos/etcd/integration imports
github.com/coreos/etcd/proxy/grpcproxy imports
google.golang.org/grpc/naming: module google.golang.org/grpc@latest found (v1.37.0), but does not contain package google.golang.org/grpc/naming
Is this a version problem? :)
服务的network这样写起不来,是什么原因了,我用的win10
s.Serve("reuseport", *addr)
in project rpcx-examples3, file consul.go have "// +build consul " ,have this code Unable to import project ,"'consul.go' doesn't match to target system.File will be ignored by build tool."
but if you delete code "// +build consul" ,it work
func addRegistryPlugin(s *server.Server) {
r := &serverplugin.ConsulRegisterPlugin{
ServiceAddress: "tcp@" + *addr,
ConsulServers: []string{*consulAddr},
BasePath: *basePath,
Metrics: metrics.NewRegistry(),
UpdateInterval: time.Minute,
}
error :
undefined: serverplugin.ConsulRegisterPlugin
我clone了代码,然后写了个脚本运行Makefile和执行docker run,然后发现rpcx_client_demo没有启动。
edzdeMacBook-Pro:docker edz$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ebd33170c5e smallnest/rpcx_server_demo:1.0 "/rpcx-service/server" 5 minutes ago Up 5 minutes 0.0.0.0:8972->8972/tcp boring_dirac
ded0eb0741de smallnest/rpcx_client_demo:1.0 "/rpcx-service/client" 5 minutes ago Exited (1) 5 minutes ago intelligent_chebyshev
看了下client报错如下:
edzdeMacBook-Pro:docker edz$ docker logs ded0
2020/06/01 10:49:13 connection.go:96: WARN : failed to dial server: dial tcp 127.0.0.1:8972: connect: connection refused
2020/06/01 10:49:13 connection.go:96: WARN : failed to dial server: dial tcp 127.0.0.1:8972: connect: connection refused
2020/06/01 10:49:13 connection.go:96: WARN : failed to dial server: dial tcp 127.0.0.1:8972: connect: connection refused
2020/06/01 10:49:13 connection.go:96: WARN : failed to dial server: dial tcp 127.0.0.1:8972: connect: connection refused
2020/06/01 10:49:13 failed to call: dial tcp 127.0.0.1:8972: connect: connection refused
2020/06/01 10:49:13 connection.go:96: WARN : failed to dial server: dial tcp 127.0.0.1:8972: connect: connection refused
自己电脑是mac pro,然后docker是19.03.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.