mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Adapt to the latest implementation
This commit is contained in:
parent
ed9d659d64
commit
65fd0ebeca
@ -84,12 +84,9 @@ public final class SentinelFeign {
|
|||||||
BeanDefinition def = gctx.getBeanDefinition(target.type().getName());
|
BeanDefinition def = gctx.getBeanDefinition(target.type().getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* Due to the change of the initialization sequence, BeanFactory.getBean will cause a circular dependency.
|
||||||
* 由于初始化顺序发生变更,这里为了避免循环依赖,只能通过 BeanDefinition 的方式获得 FeignClientFactoryBean
|
* So FeignClientFactoryBean can only be obtained from BeanDefinition
|
||||||
* 需要重点review
|
|
||||||
*/
|
*/
|
||||||
// FeignClientFactoryBean feignClientFactoryBean = (FeignClientFactoryBean) Builder.this.applicationContext
|
|
||||||
// .getBean(FACTORY_BEAN_PREFIX + target.type().getName());
|
|
||||||
FeignClientFactoryBean feignClientFactoryBean = (FeignClientFactoryBean) def.getAttribute("feignClientsRegistrarFactoryBean");
|
FeignClientFactoryBean feignClientFactoryBean = (FeignClientFactoryBean) def.getAttribute("feignClientsRegistrarFactoryBean");
|
||||||
|
|
||||||
Class fallback = feignClientFactoryBean.getFallback();
|
Class fallback = feignClientFactoryBean.getFallback();
|
||||||
|
@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package com.alibaba.cloud.sidecar.consul;
|
package com.alibaba.cloud.sidecar.consul;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.alibaba.cloud.sidecar.SidecarProperties;
|
import com.alibaba.cloud.sidecar.SidecarProperties;
|
||||||
import com.ecwid.consul.v1.agent.model.NewService;
|
import com.ecwid.consul.v1.agent.model.NewService;
|
||||||
@ -29,6 +32,8 @@ import org.springframework.cloud.consul.serviceregistry.ConsulManagementRegistra
|
|||||||
import org.springframework.cloud.consul.serviceregistry.ConsulRegistrationCustomizer;
|
import org.springframework.cloud.consul.serviceregistry.ConsulRegistrationCustomizer;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author www.itmuch.com
|
* @author www.itmuch.com
|
||||||
@ -59,12 +64,13 @@ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration {
|
|||||||
service.setAddress(sidecarProperties.getIp());
|
service.setAddress(sidecarProperties.getIp());
|
||||||
}
|
}
|
||||||
service.setName(normalizeForDns(appName));
|
service.setName(normalizeForDns(appName));
|
||||||
service.setTags(properties.getTags());
|
service.setTags(new ArrayList<>(properties.getTags()));
|
||||||
|
service.setEnableTagOverride(properties.getEnableTagOverride());
|
||||||
|
service.setMeta(getMetadata(properties));
|
||||||
|
|
||||||
// set health check, use alibaba sidecar self's port rather than polyglot app's
|
// set health check, use alibaba sidecar self's port rather than polyglot app's
|
||||||
// port.
|
// port.
|
||||||
service.setPort(
|
service.setPort(Integer.valueOf(context.getEnvironment().getProperty("server.port")));
|
||||||
Integer.valueOf(context.getEnvironment().getProperty("server.port")));
|
|
||||||
setCheck(service, autoServiceRegistrationProperties, properties, context,
|
setCheck(service, autoServiceRegistrationProperties, properties, context,
|
||||||
heartbeatProperties);
|
heartbeatProperties);
|
||||||
|
|
||||||
@ -77,6 +83,32 @@ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration {
|
|||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copyed from org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration#getMetadata
|
||||||
|
*/
|
||||||
|
private static Map<String, String> getMetadata(ConsulDiscoveryProperties properties) {
|
||||||
|
LinkedHashMap<String, String> metadata = new LinkedHashMap<>();
|
||||||
|
if (!CollectionUtils.isEmpty(properties.getMetadata())) {
|
||||||
|
metadata.putAll(properties.getMetadata());
|
||||||
|
}
|
||||||
|
|
||||||
|
// add metadata from other properties. See createTags above.
|
||||||
|
if (!StringUtils.isEmpty(properties.getInstanceZone())) {
|
||||||
|
metadata.put(properties.getDefaultZoneMetadataName(),
|
||||||
|
properties.getInstanceZone());
|
||||||
|
}
|
||||||
|
if (!StringUtils.isEmpty(properties.getInstanceGroup())) {
|
||||||
|
metadata.put("group", properties.getInstanceGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
// store the secure flag in the tags so that clients will be able to figure
|
||||||
|
// out whether to use http or https automatically
|
||||||
|
metadata.put("secure",
|
||||||
|
Boolean.toString(properties.getScheme().equalsIgnoreCase("https")));
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getInstanceId(SidecarProperties sidecarProperties,
|
public static String getInstanceId(SidecarProperties sidecarProperties,
|
||||||
Environment environment) {
|
Environment environment) {
|
||||||
return String.format("%s-%s-%s",
|
return String.format("%s-%s-%s",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user