Log warning if local instance fails.
If DiscoveryClient.getLocalServiceInstance() throws an exception (ie consul isn't available), log a warning and continue. This is useful for dev type environments. fixes gh-1603
This commit is contained in:
@@ -57,7 +57,12 @@ public class DiscoveryClientRouteLocator extends SimpleRouteLocator
|
||||
super(servletPath, properties);
|
||||
|
||||
if (properties.isIgnoreLocalService()) {
|
||||
ServiceInstance instance = discovery.getLocalServiceInstance();
|
||||
ServiceInstance instance = null;
|
||||
try {
|
||||
instance = discovery.getLocalServiceInstance();
|
||||
} catch (Exception e) {
|
||||
log.warn("Error locating local service instance", e);
|
||||
}
|
||||
if (instance != null) {
|
||||
String localServiceId = instance.getServiceId();
|
||||
if (!properties.getIgnoredServices().contains(localServiceId)) {
|
||||
|
||||
@@ -601,6 +601,19 @@ public class DiscoveryClientRouteLocatorTests {
|
||||
assertMapping(routesMap, MYSERVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalServiceExceptionIgnored() {
|
||||
given(this.discovery.getServices())
|
||||
.willReturn(Collections.<String>emptyList());
|
||||
given(this.discovery.getLocalServiceInstance()).willThrow(new RuntimeException());
|
||||
|
||||
DiscoveryClientRouteLocator routeLocator = new DiscoveryClientRouteLocator("/",
|
||||
this.discovery, this.properties);
|
||||
|
||||
// if no exception is thrown in constructor, this is a success
|
||||
routeLocator.locateRoutes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegExServiceRouteMapperNoServiceIdMatches() {
|
||||
given(this.discovery.getServices())
|
||||
|
||||
Reference in New Issue
Block a user