apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.46k stars 26.42k forks source link

[Bug] The configuration dubbo services does not take effect in the configuration file and the service is not registered #14229

Closed wangeDear closed 4 months ago

wangeDear commented 5 months ago

Pre-check

Search before asking

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

3.2.x

Steps to reproduce this issue

config services like this image

What you expected to happen

service regist success

Anything else

No response

Are you willing to submit a pull request to fix on your own?

Code of Conduct

xixingya commented 5 months ago

can you provide a demo to reproduce it

wcy666103 commented 5 months ago

Is unsuccessful registration accompanied by logging:

[DUBBO] Failed to create nacos config service client. Reason: server status check failed., dubbo version: xxx current host: xxx, error code: xxx. This may be caused by xxx

wangeDear commented 5 months ago

Using the dubbo spring boot demo of the official github, I updated the yml configuration file as follows. After startup, the service is not registered with nacos.

spring:
  application:
    name: dubbo-springboot-demo-provider

dubbo:
  application:
    name: ${spring.application.name}
  protocol:
    name: dubbo
    port: -1
  registry:
    id: nacos-registry
    address: nacos://10.133.128.64:8848?namespace=svtf_test
  config-center:
    address: nacos://10.133.128.64:8848?namespace=svtf_test
  metadata-report:
    address: nacos://10.133.128.64:8848?namespace=svtf_test
  metrics:
    protocol: prometheus
    enable-jvm: true
    enable-registry: true
    aggregation:
      enabled: true
    prometheus:
      exporter:
        enabled: true
    enable-metadata: true

  services:
    demoService:
      interface: org.apache.dubbo.springboot.demo.DemoService
      ref: demoServiceImpl

logging:
  pattern:
    level: '%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]'

DemoServiceImpl:

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.dubbo.springboot.demo.provider;

import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.springboot.demo.DemoService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

//@DubboService
@Service
public class DemoServiceImpl implements DemoService {

    private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);

    @Override
    public String sayHello(String name) {
        logger.info("Hello " + name + ", request from consumer: "
                + RpcContext.getContext().getRemoteAddress());
        return "Hello " + name;
    }
}
wangeDear commented 5 months ago

can you provide a demo to reproduce it demo updated

wangeDear commented 5 months ago

Is unsuccessful registration accompanied by logging:

[DUBBO] Failed to create nacos config service client. Reason: server status check failed., dubbo version: xxx current host: xxx, error code: xxx. This may be caused by xxx!

No

wcy666103 commented 5 months ago

Using the dubbo spring boot demo of the official github, I updated the yml configuration file as follows. After startup, the service is not registered with nacos.

spring:
  application:
    name: dubbo-springboot-demo-provider

dubbo:
  application:
    name: ${spring.application.name}
  protocol:
    name: dubbo
    port: -1
  registry:
    id: nacos-registry
    address: nacos://10.133.128.64:8848?namespace=svtf_test
  config-center:
    address: nacos://10.133.128.64:8848?namespace=svtf_test
  metadata-report:
    address: nacos://10.133.128.64:8848?namespace=svtf_test
  metrics:
    protocol: prometheus
    enable-jvm: true
    enable-registry: true
    aggregation:
      enabled: true
    prometheus:
      exporter:
        enabled: true
    enable-metadata: true

  services:
    demoService:
      interface: org.apache.dubbo.springboot.demo.DemoService
      ref: demoServiceImpl

logging:
  pattern:
    level: '%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]'

DemoServiceImpl:

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.dubbo.springboot.demo.provider;

import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.springboot.demo.DemoService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

//@DubboService
@Service
public class DemoServiceImpl implements DemoService {

    private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);

    @Override
    public String sayHello(String name) {
        logger.info("Hello " + name + ", request from consumer: "
                + RpcContext.getContext().getRemoteAddress());
        return "Hello " + name;
    }
}

To give you my configuration, I think there are two places you need to pay attention to:

  1. The matching relationship between the nacos version and the dubbo version you use
  2. Follow the nacos url with? username=yourUserName&password=yourPassword

image

xixingya commented 5 months ago

@wangeDear It seems you are using spring @Service annotation, not dubbo service annotation?why you not using @DubboService Annotation

wcy666103 commented 5 months ago

@wangeDear It seems you are using spring @service annotation, not dubbo service annotation?why you not using @DubboService Annotation

You are right ,I overlooked that detail.

You can refer to this project @wangeDear https://github.com/apache/dubbo-samples/tree/fce381c2c11f87805dede48c4f18a8e336698c1a/1-basic/dubbo-samples-spring-boot

wangeDear commented 5 months ago

@wangeDear It seems you are using spring @service annotation, not dubbo service annotation?why you not using @DubboService Annotation

So, does it mean that Dubbo service registration cannot be configured and submitted only through the yml file?

wangeDear commented 5 months ago

image

Then how is the service configuration mentioned in the documentation used?

wcy666103 commented 5 months ago

@wangeDear It seems you are using spring @service annotation, not dubbo service annotation?why you not using @DubboService Annotation

So, does it mean that Dubbo service registration cannot be configured and submitted only through the yml file?

Yes,When the project started, will be scanned to the package, and will be com.alibaba.dubbo.config.annotation.Service.class. The class Or maybe it's org.apache.dubbo.config.annotation.Service.class Or maybe it's org.apache.dubbo.config.annotation.DubboService.class The annotated classes perform service exposure and registration

wcy666103 commented 5 months ago

image

Then how is the service configuration mentioned in the documentation used?

There are tutorials and instructions on the official website, and the corresponding code in this repository that you can follow https://github.com/apache/dubbo-samples

wangeDear commented 5 months ago

image Then how is the service configuration mentioned in the documentation used?

There are tutorials and instructions on the official website, and the corresponding code in this repository that you can follow https://github.com/apache/dubbo-samples

Can you be more specific? there are no relevant configuration examples in the project you mentioned.

eye-gu commented 5 months ago

It appears that there is no configuration for services in the DubboConfigurationProperties class

xixingya commented 4 months ago

@wangeDear hello,any question? if not, this issue will close

xixingya commented 4 months ago

Summary: can not used by this way,recommend used by annotation @AlbumenJ please close this issue