RouteUtils { public static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters) { RouteRule rule = RouteRule.parseQuitely(route); Map<String, RouteRule.MatchPair> when = RouteRuleUtils.expandCondition( rule.getWhenCondition(), "consumer.cluster", "consumer.host", clusters); Map<String, String> consumerSample = ParseUtils.parseQuery("consumer.", consumerQueryUrl); final int index = consumerAddress.lastIndexOf(":"); String consumerHost = null; if(index != -1){ consumerHost = consumerAddress.substring(0, index); } else { consumerHost = consumerAddress; } consumerSample.put("consumer.host", consumerHost); return RouteRuleUtils.isMatchCondition(when, consumerSample, consumerSample); }  static boolean matchRoute(String consumerAddress, String consumerQueryUrl, Route route, Map<String, List<String>> clusters); static Map<String, String> previewRoute(String serviceName, String consumerAddress, String queryUrl, Map<String, String> serviceUrls,
            Route route, Map<String, List<String>> clusters, List<Route> routed); static List<Route> findUsedRoute(String serviceName, String consumerAddress, String consumerQueryUrl,
            List<Route> routes, Map<String, List<String>> clusters); static List<Provider> route(String serviceName, String consumerAddress, String consumerQueryUrl, List<Provider> providers,
    		List<Override> overrides, List<Route> routes, Map<String, List<String>> clusters, List<Route> routed); static Map<String, String> route(String serviceName, String consumerAddress, String consumerQueryUrl, Map<String, String> serviceUrls,
            List<Route> routes, Map<String, List<String>> clusters, List<Route> routed);  }
@Test public void test_matchRoute() throws Exception { Route route = new Route(); route.setId(1L); route.setPriority(3); route.setMatchRule("consumer.host = 1.1.2.2"); route.setFilterRule("xxx = yyy"); routes.add(route); { assertTrue(RouteUtils.matchRoute("1.1.2.2:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); assertFalse(RouteUtils.matchRoute("9.9.9.9", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); route.setMatchRule("consumer.host = 1.1.2.2 & consumer.application = kylin"); assertTrue(RouteUtils.matchRoute("1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); route.setMatchRule("consumer.host = 1.1.2.2 & consumer.application = notExstied"); assertFalse(RouteUtils.matchRoute("1.1.2.2", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", route, clusters)); } { route.setMatchRule("consumer.cluster = cluster1"); assertTrue(RouteUtils.matchRoute("7.7.7.7:20880", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); assertFalse(RouteUtils.matchRoute("9.9.9.9", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); route.setMatchRule("consumer.cluster = cluster1 & consumer.application = kylin"); assertTrue(RouteUtils.matchRoute("7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&application=kylin", route, clusters)); route.setMatchRule("consumer.cluster = cluster1 & consumer.application = notExstied"); assertFalse(RouteUtils.matchRoute("7.7.7.7", "dubbo=2.0.0&version=3.0.0&revision=3.0.0&methods=getPort,say&application=kylin", route, clusters)); } }