diff --git a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java index c6c75b16c68..5fe6c897210 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java @@ -419,6 +419,8 @@ private T createProxy(Map map) { c = true; // default true } if (c && !invoker.isAvailable()) { + // make it possible for consumer to retry later if provider is temporarily unavailable + initialized = false; throw new IllegalStateException("Failed to check the status of the service " + interfaceName + ". No provider available for the service " + (group == null ? "" : group + "/") + interfaceName + (version == null ? "" : ":" + version) + " from the url " + invoker.getUrl() + " to the consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion()); } if (logger.isInfoEnabled()) { diff --git a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ReferenceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ReferenceConfigTest.java index 888dc017cc7..e20ee390d6f 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ReferenceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ReferenceConfigTest.java @@ -59,5 +59,45 @@ public void testInjvm() throws Exception { demoService.unexport(); } } - -} \ No newline at end of file + /** + * unit test for dubbo-1765 + */ + @Test + public void testReferenceRetry() { + ApplicationConfig application = new ApplicationConfig(); + application.setName("test-reference-retry"); + RegistryConfig registry = new RegistryConfig(); + registry.setAddress("multicast://224.5.6.7:1234"); + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setName("dubbo"); + ReferenceConfig rc = new ReferenceConfig(); + rc.setApplication(application); + rc.setRegistry(registry); + rc.setInterface(DemoService.class.getName()); + boolean success = false; + DemoService demoService = null; + try { + demoService = rc.get(); + success = true; + } catch (Exception e) { + e.printStackTrace(); + } + Assert.assertFalse(success); + Assert.assertNull(demoService); + ServiceConfig sc = new ServiceConfig(); + sc.setInterface(DemoService.class); + sc.setRef(new DemoServiceImpl()); + sc.setApplication(application); + sc.setRegistry(registry); + sc.setProtocol(protocol); + try { + sc.export(); + demoService = rc.get(); + success = true; + } catch (Exception e) { + e.printStackTrace(); + } + Assert.assertTrue(success); + Assert.assertNotNull(demoService); + } +}