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

Fixed bug that nacos instance will be registered more than once, because heartbeat failed caused by light beat enabled. #3897

Merged
merged 6 commits into from Aug 4, 2021

Conversation

tw2066
Copy link
Contributor

@tw2066 tw2066 commented Aug 2, 2021

心跳因未传ip和端口 导致一直返回20404状态码

@limingxinleo
Copy link
Member

image

接口文档里没有 ip port 啊,你用最新代码试试看

@tw2066
Copy link
Contributor Author

tw2066 commented Aug 2, 2021

文档是没有 我是看java源码看到的; 感觉文档不全

    public JSONObject sendBeat(BeatInfo beatInfo, boolean lightBeatEnabled) throws NacosException {

        if (NAMING_LOGGER.isDebugEnabled()) {
            NAMING_LOGGER.debug("[BEAT] {} sending beat to server: {}", namespaceId, beatInfo.toString());
        }
        Map<String, String> params = new HashMap<String, String>(8);
        String body = StringUtils.EMPTY;
        if (!lightBeatEnabled) {
            try {
                body = "beat=" + URLEncoder.encode(JSON.toJSONString(beatInfo), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new NacosException(NacosException.SERVER_ERROR, "encode beatInfo error", e);
            }
        }
        params.put(CommonParams.NAMESPACE_ID, namespaceId);
        params.put(CommonParams.SERVICE_NAME, beatInfo.getServiceName());
        params.put(CommonParams.CLUSTER_NAME, beatInfo.getCluster());
        params.put("ip", beatInfo.getIp());
        params.put("port", String.valueOf(beatInfo.getPort()));
        String result = reqAPI(UtilAndComs.NACOS_URL_BASE + "/instance/beat", params, body, HttpMethod.PUT);
        return JSON.parseObject(result);
    }

加上之后 , 就返回正常10200 状态码了

@zxyfaxcn
Copy link
Contributor

zxyfaxcn commented Aug 2, 2021

Nacos 官网文档问题主要有:1、更新不及时 2、没有相关版本描述,所以,那个文档只起个参考意义。

@tw2066
Copy link
Contributor Author

tw2066 commented Aug 4, 2021

更新2.2.2, 有这个问题 麻烦合并一下

@alexzy228
Copy link
Contributor

这个按nacos文档,端口和ip是在beat数据里面传入的吧

@limingxinleo limingxinleo changed the title 心跳重复 20404 bug Fixed instance registered more than once when light beat enabled for nacos. Aug 4, 2021
@limingxinleo limingxinleo changed the title Fixed instance registered more than once when light beat enabled for nacos. Fixed bug that nacos instance will be registered more than once, because heartbeat failed caused by light beat enabled. Aug 4, 2021
@limingxinleo limingxinleo merged commit f19d5c4 into hyperf:master Aug 4, 2021
@limingxinleo
Copy link
Member

@tw2066 测试看看 2.2.x-dev

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

Successfully merging this pull request may close these issues.

None yet

4 participants