feat: feign eager load support schema

pull/1649/head
shedfreewu 2 months ago
parent 239cdb58b3
commit 1657d5a58b

@ -3,4 +3,4 @@
- [fix:fix PolarisContextProperties instantiated twice causing NPE.](https://github.com/Tencent/spring-cloud-tencent/pull/1639)
- [fix: fix ConfigChangeListener and unit test](https://github.com/Tencent/spring-cloud-tencent/pull/1654)
- [feat: support spring-retry and feign config refresh](https://github.com/Tencent/spring-cloud-tencent/pull/1649)
- [feat: support spring-retry and feign config refresh and feign eager load support schema](https://github.com/Tencent/spring-cloud-tencent/pull/1649)

@ -19,6 +19,7 @@ package com.tencent.cloud.polaris.eager.instrument.feign;
import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
import java.net.URI;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryClient;
import com.tencent.cloud.polaris.discovery.reactive.PolarisReactiveDiscoveryClient;
@ -60,18 +61,24 @@ public class FeignEagerLoadSmartLifecycle implements SmartLifecycle {
// if feignClient contains url, it doesn't need to eager load.
if (StringUtils.isEmpty(feignClient.url())) {
// support variables and default values.
String feignName = hardCodedTarget.name();
LOG.info("[{}] eager-load start", feignName);
String url = hardCodedTarget.name();
// refer to FeignClientFactoryBean, convert to URL, then take the host as the service name.
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://" + url;
}
String serviceName = URI.create(url).getHost();
LOG.info("[{}] eager-load start, feign name: {}", serviceName, hardCodedTarget.name());
if (polarisDiscoveryClient != null) {
polarisDiscoveryClient.getInstances(feignName);
polarisDiscoveryClient.getInstances(serviceName);
}
else if (polarisReactiveDiscoveryClient != null) {
polarisReactiveDiscoveryClient.getInstances(feignName).subscribe();
polarisReactiveDiscoveryClient.getInstances(serviceName).subscribe();
}
else {
LOG.warn("[{}] no discovery client found.", feignName);
LOG.warn("[{}] no discovery client found.", serviceName);
}
LOG.info("[{}] eager-load end", feignName);
LOG.info("[{}] eager-load end", serviceName);
}
}
}

@ -23,7 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "${provider.name:provider-demo}")
@FeignClient(name = "${provider.name:http://provider-demo}")
public interface ProviderDemoService {
@RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
String echo(@PathVariable("str") String str);

@ -52,12 +52,6 @@ public class ProviderController {
@Value("${spring.application.name:}")
private String applicationName;
@Value("${server.port:0}")
private int port;
@Value("${spring.cloud.client.ip-address:127.0.0.1}")
private String ip;
@Autowired
private ProviderNameConfig providerNameConfig;
@ -97,8 +91,8 @@ public class ProviderController {
@RequestMapping(value = "/echo/{param}", method = RequestMethod.GET)
public ResponseEntity<String> echo(@PathVariable String param) {
if (ifBadGateway) {
LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port);
return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY);
LOG.info("Provider Demo is called wrong.");
return new ResponseEntity<>("failed for call provider demo service. Address: " + getInet4Address(), HttpStatus.BAD_GATEWAY);
}
int status;

Loading…
Cancel
Save