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服务返回service discovery error: no service found #12

Open
wes-xia opened this issue May 29, 2024 · 2 comments
Open

访问RPC服务返回service discovery error: no service found #12

wes-xia opened this issue May 29, 2024 · 2 comments
Assignees

Comments

@wes-xia
Copy link

wes-xia commented May 29, 2024

问题描述

在线上RPC服务中(k8s pod中运行)调用PingMetricsClient返回service discovery error: no service found
单独写脚本在pod中执行返回正常

var (
	MetricsClient metricsservice.Client
)

func InitMetricsClient(ctx context.Context, consul_host string, consul_port string) (err error) {
	addr := fmt.Sprintf("%s:%s", consul_host, consul_port)
	r, err := consul.NewConsulResolver(addr)
	if err != nil {
		Debuger(ctx, "NewConsulResolver err:%s", err.Error())
		return
	}

	MetricsClient, err = metricsservice.NewClient(
		"ops.infra.metrics",
		client.WithMuxConnection(1),              // mux
		client.WithRPCTimeout(2*time.Second),     // rpc timeout
		client.WithConnectTimeout(2*time.Second), // conn timeout
		// client.WithFailureRetry(retry.NewFailurePolicy()), // retry
		client.WithResolver(r), // resolver
	)
	if err != nil {
		Debuger(ctx, "InitMetricsClient err:%s", err.Error())
		return
	}
	Debuger(ctx, "InitMetricsClient Success consul_host: %s consul_port: %s ", consul_host, consul_port)
	return nil
}

func PingMetricsClient(ctx context.Context) bool {
	req := &stock.Req{}
	option := callopt.WithRPCTimeout(1 * time.Second)
	_, err := MetricsClient.Ping(context.Background(), req, option)
	if err != nil {
		Debuger(ctx, "PingMetricsClient err:%s", err.Error()) //这里返回service discovery error: no service found
		return false
	}
	return true

}
@wes-xia
Copy link
Author

wes-xia commented May 29, 2024

pod单独执行

image

线上服务调用

image

@baiyutang
Copy link
Collaborator

针对报错,意思是 找不到可用实例。
这里最好参考下 服务提供者,在注册时的代码,比如注册的地址、或者服务实例的健康检查等等。

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

3 participants