diff --git a/apisix/plugin.lua b/apisix/plugin.lua index b5fe0146..a319fbc8 100644 --- a/apisix/plugin.lua +++ b/apisix/plugin.lua @@ -396,7 +396,8 @@ function _M.merge_service_route(service_conf, route_conf) core.log.info("service conf: ", core.json.delay_encode(service_conf)) core.log.info(" route conf: ", core.json.delay_encode(route_conf)) - local route_service_key = route_conf.modifiedIndex .. "#" .. service_conf.modifiedIndex + local route_service_key = route_conf.value.id .. "#" + .. route_conf.modifiedIndex .. "#" .. service_conf.modifiedIndex return merged_route(route_service_key, service_conf, merge_service_route, service_conf, route_conf) diff --git a/t/config-center-yaml/route-service.t b/t/config-center-yaml/route-service.t index 8febcd78..8876022b 100644 --- a/t/config-center-yaml/route-service.t +++ b/t/config-center-yaml/route-service.t @@ -39,6 +39,7 @@ routes: - uri: /hello service_id: 1 + id: 1 services: - id: 1 @@ -62,6 +63,7 @@ hello world routes: - uri: /hello + id: 1 service_id: 1111 services: - @@ -84,6 +86,7 @@ failed to fetch service configuration by id: 1111 --- apisix_yaml routes: - + id: 1 uri: /hello service_id: 1 services: @@ -115,6 +118,7 @@ hello world --- apisix_yaml routes: - + id: 1 uri: /hello service_id: 1 upstream: @@ -149,6 +153,7 @@ hello world --- apisix_yaml routes: - + id: 1 uri: /hello service_id: 1 upstream: @@ -184,6 +189,7 @@ hello world --- apisix_yaml routes: - + id: 1 uri: /hello service_id: 1 upstream: @@ -211,3 +217,38 @@ GET /hello hello world --- no_error_log [error] + + + +=== TEST 7: two routes with the same service +--- yaml_config eval: $::yaml_config +--- apisix_yaml +routes: + - uris: + - /hello + service_id: 1 + id: 1 + plugins: + response-rewrite: + body: "hello\n" + - uris: + - /world + service_id: 1 + id: 2 + plugins: + response-rewrite: + body: "world\n" +services: + - + id: 1 + upstream: + nodes: + "127.0.0.1:1980": 1 + type: roundrobin +#END +--- request +GET /hello +--- response_body +hello +--- no_error_log +[error] diff --git a/t/config-center-yaml/route-upstream.t b/t/config-center-yaml/route-upstream.t index 46063a81..42908daf 100644 --- a/t/config-center-yaml/route-upstream.t +++ b/t/config-center-yaml/route-upstream.t @@ -37,6 +37,7 @@ __DATA__ --- apisix_yaml routes: - + id: 1 uri: /hello upstream_id: 1 upstreams: @@ -60,6 +61,7 @@ hello world --- apisix_yaml routes: - + id: 1 uri: /hello upstream_id: 1111 upstreams: @@ -82,6 +84,7 @@ failed to find upstream by id: 1111 --- apisix_yaml routes: - + id: 1 uri: /hello upstream_id: 1 upstream: @@ -109,6 +112,7 @@ hello world --- apisix_yaml routes: - + id: 1 uri: /hello upstream_id: 1 upstreams: @@ -139,6 +143,7 @@ hello world --- apisix_yaml routes: - + id: 1 uri: /get upstream_id: 1 upstreams: diff --git a/t/config-center-yaml/route.t b/t/config-center-yaml/route.t index 972f1f05..81a37d1b 100644 --- a/t/config-center-yaml/route.t +++ b/t/config-center-yaml/route.t @@ -37,6 +37,7 @@ __DATA__ --- apisix_yaml routes: - + id: 1 uri: /hello upstream: nodes: @@ -82,6 +83,7 @@ use config_center: yaml --- apisix_yaml routes: - + id: 1 uri: /hello host: foo.com upstream: @@ -106,6 +108,7 @@ hello world stream_routes: - server_addr: 127.0.0.1 server_port: 1985 + id: 1 upstream: nodes: "127.0.0.1:1995": 1