Closed feng996 closed 3 years ago
Nacos version should upgrade to 2.0.0 or above to support service discovery model. (This is limited by Nacos)
Nacos version should upgrade to 2.0.0 or above to support service discovery model. (This is limited by Nacos)
使用2.0.2nacos也不行,dubbo协议可以,tri无法找到provider
@feng996 Can you provide a demo to help us confirming this question exists?
I have reproduced this problem, and the problem can be more specific: The Triple protocol is not working on Spring integrated with Dubbo.
There is something wrong with dubbo-spring-boot-starter
, I will try to fix it.
@feng996 I have found the cause of the problem which is not related to dubbo-spring-boot-starter
as I first thought.
The source is in org.apache.dubbo.config.metadata.ServiceInstanceHostPortCustomizer
, let's have a look:
@Override
public void customize(ServiceInstance serviceInstance) {
String host = null;
int port = -1;
// ......
Set<URL> urls = writableMetadataService.getExportedServiceURLs();
if (CollectionUtils.isNotEmpty(urls)) {
ApplicationModel applicationModel = serviceInstance.getApplicationModel();
String preferredProtocol = applicationModel.getCurrentConfig().getProtocol();
// The default value of preferredProtocol is dubbo.
if (preferredProtocol != null) {
for (URL exportedURL : urls) {
// The protocol of exportedURL is tri
// because of tri != dubbo, the host and port will not be assigned values.
if (preferredProtocol.equals(exportedURL.getProtocol())) {
host = exportedURL.getHost();
port = exportedURL.getPort();
break;
}
}
} else {
URL url = urls.iterator().next();
host = url.getHost();
port = url.getPort();
}
// If not the port of instace > 0, the application instance will not be registered to RegistryCenter(like Nacos, Zookeeper).
// As a result, the consumer can't find the avaliabe providers when our settging is registry-mode=instance
if (serviceInstance instanceof DefaultServiceInstance) {
DefaultServiceInstance instance = (DefaultServiceInstance) serviceInstance;
instance.setHost(host);
instance.setPort(port);
}
}
}
For the moment, if you want both consumer and provider to force using Application Discovery
in tri protocol, just change one line config of provider as follows:
dubbo:
application:
metadata-type: remote
register-mode: instance
protocol: tri <==== HERE, set preferredProtocol as tri
But, Dubbo official also needs to do two things for further promotion:
Relate to #8666
添加 dubbo.application.protocol=tri 3.0.4 consumer reference 还是会报no provider .... demo放在 #8987 回复里了
添加 dubbo.application.protocol=tri 3.0.4 consumer reference 还是会报no provider .... demo放在 #8987 回复里了
使用注解引用时,再次指定protocol=tri,解决 @DubboReference(providedBy = "feedback-provider", check = false, protocol = "tri") private HelloService helloService;
看起来是provider配置里services key 为interface:protocol
的原因("com.example.feedback.api.service.HelloService:tri")。
但是不知道为什么在注解引用时,并没有把dubbo.protocol.name=tri这个信息加到后面,需要在reference里再次指定
Environment
Steps to reproduce this issue
Pls. provide [GitHub address] to reproduce this issue.
Expected Result
Actual Result
If there is an exception, please attach the exception trace:
java.lang.IllegalStateException: Failed to check the status of the service service.HelloService. No provider available for the service service.HelloService from the url dubbo://