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

zk的服务发现有问题 #6

Closed
guoyu09403 opened this issue Jun 21, 2017 · 3 comments
Closed

zk的服务发现有问题 #6

guoyu09403 opened this issue Jun 21, 2017 · 3 comments

Comments

@guoyu09403
Copy link
Contributor

guoyu09403 commented Jun 21, 2017

`                // Close and remove invalid server nodes
                for (int i = 0; i < connectedHandlers.size(); ++i) {
                    RpcClientHandler connectedServerHandler = connectedHandlers.get(i);
                    SocketAddress remotePeer = connectedServerHandler.getRemotePeer();
                    if (!newAllServerNodeSet.contains(remotePeer)) {
                        LOGGER.info("Remove invalid server node " + remotePeer);
                        RpcClientHandler handler = connectedServerNodes.get(remotePeer);
                        handler.close();
                        connectedServerNodes.remove(remotePeer);
                        connectedHandlers.remove(connectedServerHandler);
                    }
                }`

再次连接同一个connectedServerNode导致connectedHandlers无法移除无效的链接

@luxiaoxun
Copy link
Owner

不太明白你的意思。
现在的做法是:遍历了所有的连接,如果某个连接不在newAllServerNodeSet就把这个连接删除,newAllServerNodeSet存储了所有的可用连接。

@gingerjiang
Copy link

代码写的真是优雅啊,向大神学习!
发现个问题,启动两个RpcBootstrapWithoutSpring 一个127.0.0.1:18866另一个127.0.0.1:18867,
写了个while循环,不断调用,停掉其中一个服务后,循环停止,不知是被哪里中断了?重新起服务,循环也不再继续
public class Test {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	ServiceDiscovery serviceDiscovery = new ServiceDiscovery("127.0.0.1:2181");
	final RpcClient rpcClient = new RpcClient(serviceDiscovery);
	int i = 100;
	while (true) {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			long startTime = System.currentTimeMillis();
			System.out.println("调用 ");
			final HelloService syncClient = rpcClient.create(HelloService.class);
			String result = syncClient.hello("asa");
			System.out.printf("%s --s \n", (System.currentTimeMillis() - startTime));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

}

@luxiaoxun
Copy link
Owner

如同@guoyu09403 所说,这个地方最开始的实现有问题:链接仅仅按照ip:port来区分是不对的,一个失败场景是:注册的服务断开后又重新练上来了,就会导致之间建立的TCP链接是“无效”的,所以添加了uuid:ip:port来区分每个链接是否存活有效。

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