From f189c949080d0ae5229bf200d0b5a99f8e9a8bbc Mon Sep 17 00:00:00 2001 From: leizhiyuan Date: Thu, 13 Dec 2018 10:51:16 +0800 Subject: [PATCH 1/3] support enableHystrix --- .../rpc/boot/config/SofaBootRpcProperties.java | 12 ++++++++++++ .../adapter/helper/ConsumerConfigHelper.java | 8 ++++++-- .../adapter/helper/ProviderConfigHelper.java | 4 ++-- .../rpc/boot/runtime/param/RpcBindingParam.java | 14 +++++++------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java index ab9bdec..b2cceb3 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java @@ -118,6 +118,8 @@ public class SofaBootRpcProperties { private String consumerRepeatedReferenceLimit; + private String enableHystrix; + public String getAftRegulationEffective() { return StringUtils.isEmpty(aftRegulationEffective) ? getDotString(new Object() { }.getClass().getEnclosingMethod().getName()) : aftRegulationEffective; @@ -544,6 +546,16 @@ public void setConsumerRepeatedReferenceLimit(String consumerRepeatedReferenceLi this.consumerRepeatedReferenceLimit = consumerRepeatedReferenceLimit; } + + public String getEnableHystrix() { + return StringUtils.isEmpty(enableHystrix) ? getDotString(new Object() { + }.getClass().getEnclosingMethod().getName()) : enableHystrix; + } + + public void setEnableHystrix(String enableHystrix) { + this.enableHystrix = enableHystrix; + } + private String getDotString(String enclosingMethodName) { if (environment == null) { return null; diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java index 84b43ad..1f22a99 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java @@ -174,8 +174,12 @@ public ConsumerConfig getConsumerConfig(Contract contract, RpcBinding binding) { consumerConfig.setSerialization(serialization); } - if (param.getParamters() != null) { - consumerConfig.setParameters(param.getParamters()); + if (param.getParameters() != null) { + consumerConfig.setParameters(param.getParameters()); + } + + if (Boolean.TRUE.toString().equals(sofaBootRpcProperties.getEnableHystrix())){ + consumerConfig.setParameter(HystrixConstants.SOFA_HYSTRIX_ENABLED,true); } return consumerConfig.setProtocol(protocol); diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ProviderConfigHelper.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ProviderConfigHelper.java index fd18fc2..9cd748e 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ProviderConfigHelper.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ProviderConfigHelper.java @@ -131,8 +131,8 @@ public ProviderConfig getProviderConfig(Contract contract, RpcBinding binding, O providerConfig.setSerialization(serialization); } - if (param.getParamters() != null) { - providerConfig.setParameters(param.getParamters()); + if (param.getParameters() != null) { + providerConfig.setParameters(param.getParameters()); } if (param.getRegistrys() != null && param.getRegistrys().size() > 0) { diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java index e506bbb..35a8d26 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java @@ -75,7 +75,7 @@ public abstract class RpcBindingParam implements BindingParam { protected String serialization; - protected Map paramters = new ConcurrentHashMap(); + protected Map parameters = new ConcurrentHashMap(); protected List registrys = new ArrayList(); @@ -429,12 +429,12 @@ public void setSerialization(String serialization) { this.serialization = serialization; } - public Map getParamters() { - return paramters; + public Map getParameters() { + return parameters; } - public void setParamters(Map paramters) { - this.paramters = paramters; + public void setParameters(Map parameters) { + this.parameters = parameters; } public List getRegistrys() { @@ -494,7 +494,7 @@ public boolean equals(Object o) { return false; if (serialization != null ? !serialization.equals(that.serialization) : that.serialization != null) return false; - if (paramters != null ? !paramters.equals(that.paramters) : that.paramters != null) + if (parameters != null ? !parameters.equals(that.parameters) : that.parameters != null) return false; return registrys != null ? registrys.equals(that.registrys) : that.registrys == null; } @@ -521,7 +521,7 @@ public int hashCode() { result = 31 * result + (methodInfos != null ? methodInfos.hashCode() : 0); result = 31 * result + (targetUrl != null ? targetUrl.hashCode() : 0); result = 31 * result + (serialization != null ? serialization.hashCode() : 0); - result = 31 * result + (paramters != null ? paramters.hashCode() : 0); + result = 31 * result + (parameters != null ? parameters.hashCode() : 0); result = 31 * result + (registrys != null ? registrys.hashCode() : 0); return result; } From 11464148e71b3b20c80c194080a37d0a442e13f7 Mon Sep 17 00:00:00 2001 From: leizhiyuan Date: Thu, 13 Dec 2018 21:32:30 +0800 Subject: [PATCH 2/3] support enableHystrix --- .../alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java | 3 +-- .../rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java | 4 ++-- .../alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java index b2cceb3..d614b05 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java @@ -118,7 +118,7 @@ public class SofaBootRpcProperties { private String consumerRepeatedReferenceLimit; - private String enableHystrix; + private String enableHystrix; public String getAftRegulationEffective() { return StringUtils.isEmpty(aftRegulationEffective) ? getDotString(new Object() { @@ -546,7 +546,6 @@ public void setConsumerRepeatedReferenceLimit(String consumerRepeatedReferenceLi this.consumerRepeatedReferenceLimit = consumerRepeatedReferenceLimit; } - public String getEnableHystrix() { return StringUtils.isEmpty(enableHystrix) ? getDotString(new Object() { }.getClass().getEnclosingMethod().getName()) : enableHystrix; diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java index 1f22a99..d6a51d8 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java @@ -178,8 +178,8 @@ public ConsumerConfig getConsumerConfig(Contract contract, RpcBinding binding) { consumerConfig.setParameters(param.getParameters()); } - if (Boolean.TRUE.toString().equals(sofaBootRpcProperties.getEnableHystrix())){ - consumerConfig.setParameter(HystrixConstants.SOFA_HYSTRIX_ENABLED,true); + if (Boolean.TRUE.toString().equals(sofaBootRpcProperties.getEnableHystrix())) { + consumerConfig.setParameter(HystrixConstants.SOFA_HYSTRIX_ENABLED, true); } return consumerConfig.setProtocol(protocol); diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java index 35a8d26..f555338 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/param/RpcBindingParam.java @@ -75,9 +75,9 @@ public abstract class RpcBindingParam implements BindingParam { protected String serialization; - protected Map parameters = new ConcurrentHashMap(); + protected Map parameters = new ConcurrentHashMap(); - protected List registrys = new ArrayList(); + protected List registrys = new ArrayList(); /** * Getter method for property timeout. From 4b5ec047452081ce1c7f5c68d0bcff73f5c77b81 Mon Sep 17 00:00:00 2001 From: leizhiyuan Date: Sat, 29 Dec 2018 12:31:12 +0800 Subject: [PATCH 3/3] hystrix enable --- .../rpc/boot/config/SofaBootRpcProperties.java | 14 ++++++-------- .../adapter/helper/ConsumerConfigHelper.java | 5 +++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java index d614b05..4ae6768 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/config/SofaBootRpcProperties.java @@ -16,10 +16,8 @@ */ package com.alipay.sofa.rpc.boot.config; -import com.alipay.sofa.rpc.common.RpcOptions; import com.alipay.sofa.rpc.common.SofaOptions; import com.google.common.base.CaseFormat; -import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.core.env.Environment; @@ -118,7 +116,7 @@ public class SofaBootRpcProperties { private String consumerRepeatedReferenceLimit; - private String enableHystrix; + private String hystrixEnable; public String getAftRegulationEffective() { return StringUtils.isEmpty(aftRegulationEffective) ? getDotString(new Object() { @@ -546,13 +544,13 @@ public void setConsumerRepeatedReferenceLimit(String consumerRepeatedReferenceLi this.consumerRepeatedReferenceLimit = consumerRepeatedReferenceLimit; } - public String getEnableHystrix() { - return StringUtils.isEmpty(enableHystrix) ? getDotString(new Object() { - }.getClass().getEnclosingMethod().getName()) : enableHystrix; + public String getHystrixEnable() { + return StringUtils.isEmpty(hystrixEnable) ? getDotString(new Object() { + }.getClass().getEnclosingMethod().getName()) : hystrixEnable; } - public void setEnableHystrix(String enableHystrix) { - this.enableHystrix = enableHystrix; + public void setHystrixEnable(String hystrixEnable) { + this.hystrixEnable = hystrixEnable; } private String getDotString(String enclosingMethodName) { diff --git a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java index d6a51d8..3aaa0fe 100644 --- a/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java +++ b/sofa-boot-core/src/main/java/com/alipay/sofa/rpc/boot/runtime/adapter/helper/ConsumerConfigHelper.java @@ -29,6 +29,7 @@ import com.alipay.sofa.rpc.config.RegistryConfig; import com.alipay.sofa.rpc.core.invoke.SofaResponseCallback; import com.alipay.sofa.rpc.filter.Filter; +import com.alipay.sofa.rpc.hystrix.HystrixConstants; import com.alipay.sofa.runtime.spi.binding.Contract; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -178,8 +179,8 @@ public ConsumerConfig getConsumerConfig(Contract contract, RpcBinding binding) { consumerConfig.setParameters(param.getParameters()); } - if (Boolean.TRUE.toString().equals(sofaBootRpcProperties.getEnableHystrix())) { - consumerConfig.setParameter(HystrixConstants.SOFA_HYSTRIX_ENABLED, true); + if (Boolean.TRUE.toString().equals(sofaBootRpcProperties.getHystrixEnable())) { + consumerConfig.setParameter(HystrixConstants.SOFA_HYSTRIX_ENABLED, Boolean.TRUE.toString()); } return consumerConfig.setProtocol(protocol);