Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc使用咨询 #19

Open
duanzonglong opened this issue Jan 9, 2023 · 2 comments
Open

rpc使用咨询 #19

duanzonglong opened this issue Jan 9, 2023 · 2 comments

Comments

@duanzonglong
Copy link

rpc服务端
package main

import (
"fmt"
"github.com/micro-plat/hydra"
"github.com/micro-plat/hydra/hydra/servers/rpc"
)

func main() {

//创建app
app := hydra.NewApp(
	hydra.WithPlatName("test"),
	hydra.WithSystemName("baseserver"),
	hydra.WithRegistry("lm://."),
	hydra.WithServerTypes(rpc.RPC),
)
hydra.Conf.RPC("192.168.31.221:8090")

//注册服务
app.RPC("/hello", func(ctx hydra.IContext) interface{} {
	fmt.Println("rpc hello")
	return "hello world"
})

//启动app
app.Start()

}
go build xxx.go
.\xxx.exe conf install
.\xxx.exe run

api服务端
package main

import (
"github.com/micro-plat/hydra"
"github.com/micro-plat/hydra/hydra/servers/http"
"github.com/micro-plat/lib4go/errs"
)

func main() {

//创建app
app := hydra.NewApp(
	hydra.WithPlatName("test"),
	hydra.WithSystemName("apiserver"),
	hydra.WithRegistry("lm://."),
	hydra.WithServerTypes(http.API),
	hydra.WithDebug(),
)
hydra.Conf.API("8080")

//注册服务
app.API("/hello", func(ctx hydra.IContext) interface{} {
	rspn := ctx.Invoke("rpc://192.168.31.221:8090")

	if !rspn.IsSuccess() {
		return errs.NewErrorf(rspn.GetStatus(), "RPC请求错误:%+v", rspn.GetError())
	}
	return rspn
})

//app.Micro()

//启动app
app.Start()

}

go build xxx.go
.\xxx.exe conf install
.\xxx.exe run
报错信息:
[2023/01/09 22:38:59.209424][i][8dadd182d]api.request: GET /hello from 192.168.199.68
[2023/01/09 22:38:59.209424][e][8dadd182d]调用RPC服务出错:rpc.client连接到服务器失败:lm://.(3)(err:rpc.client.resolver target err:未找到服务提供程序:/192/168/31/221:8090)
[2023/01/09 22:38:59.209424][e][8dadd182d]RPC请求错误:请求发生错误:rpc.client连接到服务器失败:lm://.(3)(err:rpc.client.resolver target err:未找到服务提供程序:/192/168/31/221:8090)

环境信息:win10 go版本 1.19.4

@duanzonglong
Copy link
Author

有没有建个qq群啊 有问题好互相帮助啊 这个框架比github上其他几个框架的设计都好很多

@duanzonglong
Copy link
Author

当使用内存作为注册中心的时候 客户端和服务端 不是同一个内存 因此是有问题的 改成redis后 需要改成
rspn := ctx.Invoke("rpc://hello") 文档太缺乏了 摸索几天才发现这些问题的 后面看到的人 少走弯路

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant