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

Service cannot registered, openAPI query result not consistent #1712

Closed
evancyz opened this issue Aug 17, 2019 · 8 comments
Closed

Service cannot registered, openAPI query result not consistent #1712

evancyz opened this issue Aug 17, 2019 · 8 comments
Assignees
Labels
kind/bug Category issues or prs related to bug.

Comments

@evancyz
Copy link

evancyz commented Aug 17, 2019

hello ,
I use nacos-sync to sync zkRegister to nacoRsegister

when i sync one service , in the nacos op, it looks like right
image

but, when i use consumer, it can not find provider

i use openAPI try to solve question:
image
when i use this command, it looks like ok

bug when i use this command
image
hosts is empty。
Was the registration successful?

@nacos-bot nacos-bot added the kind/bug Category issues or prs related to bug. label Aug 17, 2019
@evancyz
Copy link
Author

evancyz commented Aug 17, 2019

when my consumer start, in nacos backgroup it likes that 。
then the dubbo error, can not find provider

image

@evancyz
Copy link
Author

evancyz commented Aug 17, 2019

I found the answer on my IDE console:
request for registration like that :
http://xxxxx:8848/nacos/v1/ns/instance/list?healthyOnly=false&namespaceId=public&clientIP=192.168.1.8&serviceName=DEFAULT_GROUP@@providers:com.xxx.xxx.api.service.xxxService:1.0.0:&udpPort=61054&encoding=UTF-8

com.xxx.xxx.api.service.xxxService:1.0.0:

in the last, it has the extra ":"
(:

it is the bug?

@evancyz
Copy link
Author

evancyz commented Aug 17, 2019

I found the question is on:

org.apache.dubbo.registry.nacos.getServiceName
use the util : org.apache.dubbo.common.getColonSeparatedKey to generate consumer

if the group name is blank
in the end, it will append the " : "

(:
this is the bug ? i dont have the groupName in the old project , it not process well i guess
image

@evancyz
Copy link
Author

evancyz commented Aug 18, 2019

I find the URLTest in dubbo project

it looks like the extra ":" is expected


    @Test
    public void testGetColonSeparatedKey() {
        URL url1 = URL.valueOf("10.20.130.230:20880/context/path?interface=org.apache.dubbo.test.interfaceName&group=group&version=1.0.0");
        Assertions.assertEquals("org.apache.dubbo.test.interfaceName:1.0.0:group", url1.getColonSeparatedKey());

        URL url2 = URL.valueOf("10.20.130.230:20880/context/path?interface=org.apache.dubbo.test.interfaceName&version=1.0.0");
        Assertions.assertEquals("org.apache.dubbo.test.interfaceName:1.0.0:", url2.getColonSeparatedKey());

        URL url3 = URL.valueOf("10.20.130.230:20880/context/path?interface=org.apache.dubbo.test.interfaceName&group=group");
        Assertions.assertEquals("org.apache.dubbo.test.interfaceName::group", url3.getColonSeparatedKey());

        URL url4 = URL.valueOf("10.20.130.230:20880/context/path?interface=org.apache.dubbo.test.interfaceName");
        Assertions.assertEquals("org.apache.dubbo.test.interfaceName::", url4.getColonSeparatedKey());
    }

image

Who is responsible? nacos or nacos-sync?
i think the nacos-sync find the service and sync success

@evancyz
Copy link
Author

evancyz commented Aug 18, 2019

i search the answer in nacos-sync project

nacos-sync use nacos NamingService to register service

in the ZookeeperSyncToNacosServiceImpl#getServiceNameFromCache,the method is generate the service name

the code display:

    /**
     * cteate Dubbo service name
     *
     * @param taskId task id
     * @param queryParam dubbo metadata
     */
    protected String getServiceNameFromCache(String taskId, Map<String, String> queryParam) {
        return nacosServiceNameMap
                .computeIfAbsent(taskId, (key) -> Joiner.on(":").skipNulls().join(CATALOG_KEY,
                        queryParam.get(INTERFACE_KEY), queryParam.get(VERSION_KEY),
                        queryParam.get(GROUP_KEY)));
    }

in the nacos-sync entity task,the dubbo group is "",not the null
but,above the method,the field Map<String, String> queryParam is the zookeeper entity,so the GROUP_KEY is null。

this is the answer (:

i will give the nacos-sync issue (:

but i think the “:” in the end is not pretty

Thank you!

@chuntaojun
Copy link
Collaborator

We will go to repair the nacos - sync components problem

@paderlol
Copy link
Collaborator

// 这是 2.7.5
String parameterValue = this.getParameter(parameterName);
        if (!StringUtils.isBlank(parameterValue)) {
            if (!first) {
                target.append(":");
            }
            target.append(parameterValue);
        } else {
            target.append(":");
        }
// 2.6.x

    private String getServiceName(URL url, String category) {
        StringBuilder serviceNameBuilder = new StringBuilder(category);
        appendIfPresent(serviceNameBuilder, url, Constants.INTERFACE_KEY);
        appendIfPresent(serviceNameBuilder, url, Constants.VERSION_KEY);
        appendIfPresent(serviceNameBuilder, url, Constants.GROUP_KEY);
        return serviceNameBuilder.toString();
    }

    private void appendIfPresent(StringBuilder target, URL url, String parameterName) {
        String parameterValue = url.getParameter(parameterName);
        if (!StringUtils.isBlank(parameterValue)) {
            target.append(SERVICE_NAME_SEPARATOR).append(parameterValue);
        }
    }

This is a Dubbo version issue, Without about a problem with Nacos Sync. I consider if there is a way to solve this problem.

@paderlol paderlol self-assigned this Jan 10, 2020
@paderlol
Copy link
Collaborator

This issue has been resolved, you can use version 0.3.5 of Nacos Sync.
PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Category issues or prs related to bug.
Projects
None yet
Development

No branches or pull requests

4 participants