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

不能连接nacos客户端 #720

Open
Ambition6666 opened this issue Jan 28, 2024 · 4 comments
Open

不能连接nacos客户端 #720

Ambition6666 opened this issue Jan 28, 2024 · 4 comments

Comments

@Ambition6666
Copy link

跟着kitex官方文档敲的,一直连接报错, nacos用的是1.几的版本,单节点
image

package main

import (
	"fmt"
	"github.com/cloudwego/kitex/pkg/rpcinfo"
	"github.com/cloudwego/kitex/server"
	"github.com/kitex-contrib/registry-nacos/v2/registry"
	"github.com/nacos-group/nacos-sdk-go/v2/clients"
	"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
	"github.com/nacos-group/nacos-sdk-go/v2/vo"
	"log"
	userdemo "micro/kitex_gen/userdemo/userservice"
	"net"
)

func main() {

	sc := []constant.ServerConfig{
		*constant.NewServerConfig("xxxxxxx", 8848, constant.WithContextPath("/nacos"), constant.WithScheme("http")),
	}

	cc := constant.ClientConfig{

		NamespaceId:         "public",
		TimeoutMs:           50000,
		NotLoadCacheAtStart: true,
		Username:            "nacos",
		Password:            "nb666",
	}

	cli, err := clients.NewNamingClient(
		vo.NacosClientParam{
			ClientConfig:  &cc,
			ServerConfigs: sc,
		},
	)
	if err != nil {
		fmt.Println("cli错误")
		panic(err)
	}

	//success, err := cli.RegisterInstance(vo.RegisterInstanceParam{
	//	Ip:          "xxxxxx",
	//	Port:        8848,
	//	ServiceName: "user",
	//	Weight:      10,
	//	Enable:      true,
	//	Healthy:     true,
	//	Ephemeral:   true,
	//	Metadata:    map[string]string{"idc": "shanghai"},
	//})
	//
	//if !success {
	//	panic(err)
	//}

	svr := userdemo.NewServer(
		new(UserServiceImpl),
		server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "user"}),
		server.WithServiceAddr(&net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 9090}),
		server.WithRegistry(registry.NewNacosRegistry(cli, registry.WithCluster("DEFAULT"), registry.WithGroup("DEFAULT_GROUP"))),
	)
	if err := svr.Run(); err != nil {
		log.Println("server stopped with error:", err)
	} else {
		log.Println("server stopped")
	}

}
@binbin0325
Copy link
Member

这是2.x的客户端,需要链接nacos server 2.x

@Ambition6666
Copy link
Author

Ambition6666 commented Jan 30, 2024

这是2.x的客户端,需要链接nacos server 2.x

nacos2.x几好像grpc偏移端口需要搭集群, 所以我就弄了个nacos1.x的服务端, 那如果我要连接1,x的服务端, 用v1版的包吗

@binbin0325
Copy link
Member

这是2.x的客户端,需要链接nacos server 2.x

nacos2.x几好像grpc偏移端口需要搭集群, 所以我就弄了个nacos1.x的服务端, 那如果我要连接1,x的服务端, 用v1版的包吗

是的

@Ambition6666
Copy link
Author

这是2.x的客户端,需要链接nacos server 2.x

nacos2.x几好像grpc偏移端口需要搭集群, 所以我就弄了个nacos1.x的服务端, 那如果我要连接1,x的服务端, 用v1版的包吗

是的

好的,谢谢

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

2 participants