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

zookeeper 集群问题 #154

Open
miibyxs opened this issue Apr 17, 2019 · 3 comments
Open

zookeeper 集群问题 #154

miibyxs opened this issue Apr 17, 2019 · 3 comments

Comments

@miibyxs
Copy link

miibyxs commented Apr 17, 2019

注册中心使用zookeeper集群方式时,服务无法正常注册到注册中心

日志信息如下:

  • server.ERROR
Log file created at: 2019/04/17 16:05:36
Running on machine: noone
Binary: Built with gc go1.12.4 for linux/amd64
Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg
E0417 16:05:36.055643   12645 motan.go:282] [ZkRegistry] connect server error. err:lookup : no such host
  • client.ERROR
Log file created at: 2019/04/17 16:05:57
Running on machine: noone
Binary: Built with gc go1.12.4 for linux/amd64
Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg

执行 go run client.go 时有如下输出:

start parse config path:./../conf/motan-client.yaml 
load mybasicRefer configuration success. url: motan2://:0/cn.interfaces.rpc.MotanDemoService?group=motan-demo-rpc
use log dir:./clientlogs
motan call fail! err:No referers for request, RequestID: 0, Request info: map[M_g:motan-demo-rpc M_mdu: M_p:cn.interfaces.rpc.MotanDemoService M_s:client-test M_v:]

zookeeper 集群是使用 docker 搭建的,同样情况下我使用 Java 则不存在这个问题,基本可以排除 zookeeper 集群的问题。

<!-- java: motan-server.xml -->
<motan:registry regProtocol="zookeeper" name="my_zookeeper" address="127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183"/>

另外当 zk-registry 中配置 hostport 为任意一个 zookeeper 节点时,都可以正常运行

motan-registry:
  zk-registry:
    protocol: zookeeper
    host: 127.0.0.1
    port: 2181
    registrySessionTimeout: 10000

请问一下,这个可能是什么原因引起的?

具体配置如下:

  • motan-server.yaml
#config fo server
motan-server:
  log_dir: "./serverlogs"
  application: "server-test"

#config of registries
motan-registry:
  zk-registry:
    protocol: zookeeper
    address: "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183"
    registrySessionTimeout: 10000

#conf of basic service
motan-basicService:
  mybasicService:
    application: "server-test"
    group: motan-demo-rpc
    protocol: motan2
    registry: zk-registry
    haStrategy: failover
    loadbalance: roundrobin
    serialization: simple
    nodeType: server

#conf of services
motan-service:
  mytest-demo:
    path: cn.interfaces.rpc.MotanDemoService
    basicService: mybasicService
    ref : "main.MotanDemoService"
    export: "motan2:8009"
  • motan-client.yaml
#config fo client
motan-client:
  log_dir: "./clientlogs"
  application: "client-test"

#config of registries
motan-registry:
  zk-registry:
    protocol: zookeeper
    address: "127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183"
    registrySessionTimeout: 10000

#conf of basic refers
motan-basicRefer:
  mybasicRefer:
    application: "client-test"
    group: motan-demo-rpc
    protocol: motan2
    registry: zk-registry
    requestTimeout: 1000
    haStrategy: failover
    loadbalance: roundrobin
    serialization: simple
    retries: 1

#conf of refers
motan-refer:
  mytest-demo:
    path: cn.interfaces.rpc.MotanDemoService
    basicRefer: mybasicRefer

代码如下:

  • server.go
package main

import (
	"fmt"
	"time"

	"github.com/weibocom/motan-go"
)

func main() {
	runServer()
}

func runServer() {
	mscontext := motan.GetMotanServerContext("./../conf/motan-server.yaml")
	mscontext.RegisterService(&MotanDemoService{}, "")
	mscontext.Start(nil)
	mscontext.ServicesAvailable() //注册服务后,默认并不提供服务,调用此方法后才会正式提供服务。需要根据实际使用场景决定提供服务的时机。作用与java版本中的服务端心跳开关一致。
	time.Sleep(time.Second * 50000000)
}

type MotanDemoService struct{}

func (m *MotanDemoService) Hello(name string) string {
	fmt.Printf("MotanDemoService hello:%s\n", name)
	return "hello " + name
}
  • client.go
package main

import (
	"fmt"

	"github.com/weibocom/motan-go"
)

func main() {
	runClient()
}

func runClient() {
	mccontext := motan.GetClientContext("./../conf/motan-client.yaml")
	mccontext.Start(nil)

	var reply string

	mclient := mccontext.GetClient("mytest-demo")
	err := mclient.Call("hello", []interface{}{"Golang"}, &reply)
	if err != nil {
		fmt.Printf("motan call fail! err:%v\n", err)
	} else {
		fmt.Printf("motan call success! reply:%s\n", reply)
	}
}
@Zha-Zha
Copy link
Contributor

Zha-Zha commented Apr 17, 2019

感谢反馈问题!
该问题已经定位,是zookeeper模块的address获取有问题
马上修复,merge代码后回复您

@Zha-Zha
Copy link
Contributor

Zha-Zha commented Apr 17, 2019

@Lizhg 问题已经解决,请更新一下代码
pr: #155
commit: bd795a9

@miibyxs
Copy link
Author

miibyxs commented Apr 17, 2019

@Zha-Zha 好的,感谢。

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