feat: 改成feign调用,支持上报prometheus

pull/193/head
andrewshan 3 years ago
commit 0cb656a98b

@ -17,21 +17,16 @@
package com.tencent.cloud.polaris.router.grayrelease.back;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
@RequestMapping("/router/gray")
public class BackController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private Environment environment;

@ -18,23 +18,21 @@
package com.tencent.cloud.polaris.router.grayrelease.front;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
@RequestMapping("/router/gray")
public class FrontController {
@Autowired
private RestTemplate restTemplate;
private Environment environment;
@Autowired
private Environment environment;
private RouterService routerService;
/**
* Get information of callee.
@ -45,7 +43,7 @@ public class FrontController {
String env = System.getenv("SCT_METADATA_CONTENT_env");
String appName = environment.getProperty("spring.application.name");
String curName = appName + "[" + env + "]";
String resp = restTemplate.getForObject("http://gray-release-middle/router/gray/rest", String.class);
String resp = routerService.rest();
return curName + " -> " + resp;
}
}

@ -20,20 +20,13 @@ package com.tencent.cloud.polaris.router.grayrelease.front;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class GrayReleaseFrontApplication {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(GrayReleaseFrontApplication.class, args);
}

@ -0,0 +1,35 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
*/
package com.tencent.cloud.polaris.router.grayrelease.front;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* Router callee feign client.
*
* @author lepdou 2022-04-06
*/
@FeignClient("gray-release-middle")
public interface RouterService {
@GetMapping("/router/gray/rest")
String rest();
}

@ -13,6 +13,11 @@
<artifactId>router-grayrelease-gateway</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
<groupId>com.tencent.cloud</groupId>
@ -37,11 +42,6 @@
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-metadata-transfer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
</dependencies>
<build>

@ -23,17 +23,16 @@ import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
@RequestMapping("/router/gray")
public class GatewayController {
@Autowired
private RestTemplate restTemplate;
private Environment environment;
@Autowired
private Environment environment;
private RouterService routerService;
/**
* Get information of callee.
@ -42,7 +41,7 @@ public class GatewayController {
@GetMapping("/entry")
public String rest() {
String appName = environment.getProperty("spring.application.name");
String resp = restTemplate.getForObject("http://gray-release-front/router/gray/rest", String.class);
String resp = routerService.rest();
return appName + " -> " + resp;
}
}

@ -20,20 +20,13 @@ package com.tencent.cloud.polaris.router.grayrelease.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class GrayReleaseGatewayApplication {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(GrayReleaseGatewayApplication.class, args);
}

@ -0,0 +1,38 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
*/
package com.tencent.cloud.polaris.router.grayrelease.gateway;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Router callee feign client.
*
* @author lepdou 2022-04-06
*/
@FeignClient("gray-release-front")
public interface RouterService {
@GetMapping("/router/gray/rest")
String rest();
}

@ -20,20 +20,13 @@ package com.tencent.cloud.polaris.router.grayrelease.middle;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class GrayReleaseMiddleApplication {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(GrayReleaseMiddleApplication.class, args);
}

@ -18,23 +18,21 @@
package com.tencent.cloud.polaris.router.grayrelease.middle;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
@RequestMapping("/router/gray")
public class MiddleController {
@Autowired
private RestTemplate restTemplate;
private Environment environment;
@Autowired
private Environment environment;
private RouterService routerService;
/**
* Get information of callee.
@ -45,7 +43,7 @@ public class MiddleController {
String env = System.getenv("SCT_METADATA_CONTENT_env");
String appName = environment.getProperty("spring.application.name");
String curName = appName + "[" + env + "]";
String resp = restTemplate.getForObject("http://gray-release-back/router/gray/rest", String.class);
String resp = routerService.rest();
return curName + " -> " + resp;
}
}

@ -0,0 +1,35 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
*/
package com.tencent.cloud.polaris.router.grayrelease.middle;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* Router callee feign client.
*
* @author lepdou 2022-04-06
*/
@FeignClient("gray-release-back")
public interface RouterService {
@GetMapping("/router/gray/rest")
String rest();
}
Loading…
Cancel
Save