xionglinrurrection opened a new issue, #12954: URL: https://github.com/apache/dubbo/issues/12954
<!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy --> - [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate. ### Environment * Dubbo version: 2.7.7 * Operating System version: macOS Big Sur 11.5.1 * Java version: 1.8.0_231 ### Steps to reproduce this issue 1. API Interface ``` public interface DemoService { String sayHello(String name); } ``` 2. provider xml config ``` <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <dubbo:application metadata-type="remote" name="demo-provider" /> <dubbo:metadata-report address="zookeeper://127.0.0.1:2181" /> <dubbo:registry address="zookeeper://127.0.0.1:2181" id="bearZK" > <dubbo:parameter key="registry-type" value="service"></dubbo:parameter> </dubbo:registry> <dubbo:protocol name="dubbo"/> <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl" /> <dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService" version="1.0" registry="bearZK" /> </beans> ``` 3. provider 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 + ", response from provider: " + RpcContext.getContext().getLocalAddress(); } } ``` 4. provider main ``` public class ApplicationProvider { public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider.xml"); context.start(); System.in.read(); } } ``` 5. consumer xml config ``` <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <dubbo:application name="demo-consumer" /> <dubbo:metadata-report address="zookeeper://127.0.0.1:2181"/> <dubbo:registry address="zookeeper://127.0.0.1:2181" id="bearZk"> <dubbo:parameter key="registry-type" value="service"></dubbo:parameter> </dubbo:registry> <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService" version="1.0" /> </beans> ``` 6. consumer main ``` public class ApplicationConsumer { public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml"); context.start(); DemoService demoService = context.getBean("demoService", DemoService.class); demoService.sayHello("test"); } } ``` ### Expected Behavior <!-- What do you expect from the above steps?--> ### Actual Behavior Exception in thread "main" org.apache.dubbo.rpc.RpcException: Failed to invoke the method sayHello in the service org.apache.dubbo.demo.DemoService. No provider available for the service org.apache.dubbo.demo.DemoService:1.0 from registry 127.0.0.1:2181 on the consumer 127.0.0.1 using the dubbo version . Please check if the providers have been started and registered. If there is an exception, please attach the exception trace: Exception in thread "main" org.apache.dubbo.rpc.RpcException: Failed to invoke the method sayHello in the service org.apache.dubbo.demo.DemoService. No provider available for the service org.apache.dubbo.demo.DemoService:1.0 from registry 127.0.0.1:2181 on the consumer 127.0.0.1 using the dubbo version . Please check if the providers have been started and registered. at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.checkInvokers(AbstractClusterInvoker.java:328) at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:60) at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:305) at org.apache.dubbo.rpc.cluster.interceptor.ClusterInterceptor.intercept(ClusterInterceptor.java:38) at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$InterceptorInvokerNode.invoke(AbstractCluster.java:101) at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:91) at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:86) at org.apache.dubbo.common.bytecode.proxy0.sayHello(proxy0.java) at org.apache.dubbo.demo.consumer.ApplicationConsumer.main(ApplicationConsumer.java:32) ## Analyse org.apache.dubbo.registry.client.ServiceDiscoveryRegistry#getExportedURLs(org.apache.dubbo.registry.client.ServiceInstance) -->org.apache.dubbo.metadata.MetadataService#getExportedURLs() -->org.apache.dubbo.registry.client.metadata.proxy.RemoteMetadataServiceProxy#getExportedURLs -->org.apache.dubbo.metadata.MetadataService#getExportedURLs(java.lang.String) [param is "*"] --->org.apache.dubbo.metadata.MetadataService#getExportedURLs(java.lang.String, java.lang.String, java.lang.String, java.lang.String) [param is "*", null, null, null] <img width="974" alt="image" src="https://github.com/apache/dubbo/assets/33899503/da776a4d-25f4-453b-a15c-330fc8a53fd7"> when serviceInterface is "*", this path is empty . that leads to no zk path in order to find instance exported urls <img width="645" alt="image" src="https://github.com/apache/dubbo/assets/33899503/b1240123-93f4-4b82-88a0-90b9d58724b3"> ## bug fix 1. get serviceKey according to subscribedURL ``` private List<URL> getExportedURLs(URL subscribedURL, ServiceInstance providerServiceInstance) { List<URL> exportedURLs = null; String metadataStorageType = getMetadataStorageType(providerServiceInstance); try { MetadataService metadataService = MetadataServiceProxyFactory.getExtension(metadataStorageType) .getProxy(providerServiceInstance); if (metadataService != null) { String anInterface = subscribedURL.getParameter("interface"); String group = subscribedURL.getParameter("group"); String version = subscribedURL.getParameter("version"); String protocol = subscribedURL.getParameter("protocol", "dubbo"); SortedSet<String> urls = metadataService.getExportedURLs(anInterface, group, version,protocol); exportedURLs = toURLs(urls); } } catch (Throwable e) { if (logger.isErrorEnabled()) { logger.error(format("Failed to get the exported URLs from the target service instance[%s]", providerServiceInstance), e); } exportedURLs = null; // set the result to be null if failed to get } return exportedURLs; } ``` <img width="961" alt="image" src="https://github.com/apache/dubbo/assets/33899503/7ef696d7-84bc-4cb0-9f2e-1d6b1b1800cf"> 3. RemoteMetadataServiceProxy#getExportedURLs chang params order ``` @Override public SortedSet<String> getExportedURLs(String serviceInterface, String group, String version, String protocol) { return toSortedStrings(getMetadataReport().getExportedURLs( new ServiceMetadataIdentifier(serviceInterface, version, group, PROVIDER_SIDE, revision, protocol))); } ``` <img width="1050" alt="image" src="https://github.com/apache/dubbo/assets/33899503/3b37587f-c2c0-4cde-b367-25f1d3c160b0"> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org