mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
remote all hystrix,zuul,ribbon
This commit is contained in:
@@ -33,11 +33,6 @@
|
||||
<artifactId>sentinel-parameter-flow-control</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-zuul-adapter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
|
||||
|
@@ -17,28 +17,17 @@
|
||||
package com.alibaba.cloud.sentinel.gateway;
|
||||
|
||||
import com.alibaba.cloud.sentinel.gateway.scg.SentinelGatewayProperties;
|
||||
import com.alibaba.cloud.sentinel.gateway.zuul.SentinelZuulProperties;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
public final class ConfigConstants {
|
||||
|
||||
/**
|
||||
* Netflix Zuul type.
|
||||
*/
|
||||
public static final String APP_TYPE_ZUUL_GATEWAY = "12";
|
||||
|
||||
/**
|
||||
* Spring Cloud Gateway type.
|
||||
*/
|
||||
public static final String APP_TYPE_SCG_GATEWAY = "11";
|
||||
|
||||
/**
|
||||
* ConfigurationProperties for {@link SentinelZuulProperties}.
|
||||
*/
|
||||
public static final String ZUUL_PREFIX = "spring.cloud.sentinel.zuul";
|
||||
|
||||
/**
|
||||
* ConfigurationProperties for {@link SentinelGatewayProperties}.
|
||||
*/
|
||||
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.alibaba.cloud.sentinel.gateway.zuul;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.DefaultBlockFallbackProvider;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackManager;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* @author tiger
|
||||
*/
|
||||
public class FallBackProviderHandler implements SmartInitializingSingleton {
|
||||
|
||||
private static final Logger logger = LoggerFactory
|
||||
.getLogger(FallBackProviderHandler.class);
|
||||
|
||||
private final DefaultListableBeanFactory beanFactory;
|
||||
|
||||
public FallBackProviderHandler(DefaultListableBeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
Map<String, ZuulBlockFallbackProvider> providerMap = beanFactory
|
||||
.getBeansOfType(ZuulBlockFallbackProvider.class);
|
||||
if (!CollectionUtils.isEmpty(providerMap)) {
|
||||
providerMap.forEach((k, v) -> {
|
||||
logger.info("[Sentinel Zuul] Register provider name:{}, instance: {}", k,
|
||||
v);
|
||||
ZuulBlockFallbackManager.registerProvider(v);
|
||||
});
|
||||
}
|
||||
else {
|
||||
logger.info("[Sentinel Zuul] Register default fallback provider. ");
|
||||
ZuulBlockFallbackManager.registerProvider(new DefaultBlockFallbackProvider());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
///*
|
||||
// * Copyright 2013-2018 the original author or authors.
|
||||
// *
|
||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// * you may not use this file except in compliance with the License.
|
||||
// * You may obtain a copy of the License at
|
||||
// *
|
||||
// * https://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * 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.alibaba.cloud.sentinel.gateway.zuul;
|
||||
//
|
||||
//import java.util.Optional;
|
||||
//
|
||||
//import javax.annotation.PostConstruct;
|
||||
//
|
||||
//import com.alibaba.cloud.sentinel.gateway.ConfigConstants;
|
||||
//import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser;
|
||||
//import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.ZuulGatewayCallbackManager;
|
||||
//import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter;
|
||||
//import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter;
|
||||
//import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter;
|
||||
//import com.alibaba.csp.sentinel.config.SentinelConfig;
|
||||
//import com.netflix.zuul.http.ZuulServlet;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//
|
||||
///**
|
||||
// * Sentinel Spring Cloud Zuul AutoConfiguration.
|
||||
// *
|
||||
// * @author tiger
|
||||
// */
|
||||
//@Configuration(proxyBeanMethods = false)
|
||||
//@ConditionalOnClass(ZuulServlet.class)
|
||||
//@ConditionalOnProperty(prefix = ConfigConstants.ZUUL_PREFIX, name = "enabled",
|
||||
// havingValue = "true", matchIfMissing = true)
|
||||
//@EnableConfigurationProperties(SentinelZuulProperties.class)
|
||||
//public class SentinelZuulAutoConfiguration {
|
||||
//
|
||||
// private static final Logger logger = LoggerFactory
|
||||
// .getLogger(SentinelZuulAutoConfiguration.class);
|
||||
//
|
||||
// @Autowired
|
||||
// private Optional<RequestOriginParser> requestOriginParserOptional;
|
||||
//
|
||||
// @Autowired
|
||||
// private SentinelZuulProperties zuulProperties;
|
||||
//
|
||||
// @PostConstruct
|
||||
// private void init() {
|
||||
// requestOriginParserOptional
|
||||
// .ifPresent(ZuulGatewayCallbackManager::setOriginParser);
|
||||
// System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY,
|
||||
// String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY));
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// @ConditionalOnMissingBean
|
||||
// public SentinelZuulPreFilter sentinelZuulPreFilter() {
|
||||
// logger.info("[Sentinel Zuul] register SentinelZuulPreFilter {}",
|
||||
// zuulProperties.getOrder().getPre());
|
||||
// return new SentinelZuulPreFilter(zuulProperties.getOrder().getPre());
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// @ConditionalOnMissingBean
|
||||
// public SentinelZuulPostFilter sentinelZuulPostFilter() {
|
||||
// logger.info("[Sentinel Zuul] register SentinelZuulPostFilter {}",
|
||||
// zuulProperties.getOrder().getPost());
|
||||
// return new SentinelZuulPostFilter(zuulProperties.getOrder().getPost());
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// @ConditionalOnMissingBean
|
||||
// public SentinelZuulErrorFilter sentinelZuulErrorFilter() {
|
||||
// logger.info("[Sentinel Zuul] register SentinelZuulErrorFilter {}",
|
||||
// zuulProperties.getOrder().getError());
|
||||
// return new SentinelZuulErrorFilter(zuulProperties.getOrder().getError());
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public FallBackProviderHandler fallBackProviderHandler(
|
||||
// DefaultListableBeanFactory beanFactory) {
|
||||
// return new FallBackProviderHandler(beanFactory);
|
||||
// }
|
||||
//
|
||||
//}
|
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.alibaba.cloud.sentinel.gateway.zuul;
|
||||
|
||||
import com.alibaba.cloud.sentinel.gateway.ConfigConstants;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.constants.ZuulConstant;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
@ConfigurationProperties(prefix = ConfigConstants.ZUUL_PREFIX)
|
||||
public class SentinelZuulProperties {
|
||||
|
||||
@NestedConfigurationProperty
|
||||
private SentinelZuulProperties.Order order = new SentinelZuulProperties.Order();
|
||||
|
||||
public Order getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public SentinelZuulProperties setOrder(Order order) {
|
||||
this.order = order;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Order {
|
||||
|
||||
/**
|
||||
* The order of {@link SentinelZuulPreFilter}.
|
||||
*/
|
||||
private int pre = 10000;
|
||||
|
||||
/**
|
||||
* The order of {@link SentinelZuulPostFilter}.
|
||||
*/
|
||||
private int post = ZuulConstant.SEND_RESPONSE_FILTER_ORDER;
|
||||
|
||||
/**
|
||||
* The order of {@link SentinelZuulErrorFilter}.
|
||||
*/
|
||||
private int error = -1;
|
||||
|
||||
public int getPre() {
|
||||
return pre;
|
||||
}
|
||||
|
||||
public void setPre(int pre) {
|
||||
this.pre = pre;
|
||||
}
|
||||
|
||||
public int getPost() {
|
||||
return post;
|
||||
}
|
||||
|
||||
public void setPost(int post) {
|
||||
this.post = post;
|
||||
}
|
||||
|
||||
public int getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(int error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -38,14 +38,6 @@ import org.springframework.context.annotation.Scope;
|
||||
@AutoConfigureBefore(FeignAutoConfiguration.class)
|
||||
public class SeataFeignClientAutoConfiguration {
|
||||
|
||||
// @Bean
|
||||
// @Scope("prototype")
|
||||
// @ConditionalOnClass(name = "com.netflix.hystrix.HystrixCommand")
|
||||
// @ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "true")
|
||||
// Feign.Builder feignHystrixBuilder(BeanFactory beanFactory) {
|
||||
// return SeataHystrixFeignBuilder.builder(beanFactory);
|
||||
// }
|
||||
|
||||
@Bean
|
||||
@Scope("prototype")
|
||||
@ConditionalOnClass(name = "com.alibaba.csp.sentinel.SphU")
|
||||
|
@@ -24,10 +24,7 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
|
||||
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
||||
//import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||
import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient;
|
||||
//import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
|
||||
//import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
@@ -39,9 +36,6 @@ public class SeataFeignObjectWrapper {
|
||||
|
||||
private final BeanFactory beanFactory;
|
||||
|
||||
// private CachingSpringLoadBalancerFactory cachingSpringLoadBalancerFactory;
|
||||
|
||||
// private SpringClientFactory springClientFactory;
|
||||
|
||||
SeataFeignObjectWrapper(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
@@ -49,11 +43,6 @@ public class SeataFeignObjectWrapper {
|
||||
|
||||
Object wrap(Object bean) {
|
||||
if (bean instanceof Client && !(bean instanceof SeataFeignClient)) {
|
||||
// if (bean instanceof LoadBalancerFeignClient) {
|
||||
// LoadBalancerFeignClient client = ((LoadBalancerFeignClient) bean);
|
||||
// return new SeataLoadBalancerFeignClient(client.getDelegate(), factory(),
|
||||
// clientFactory(), this);
|
||||
// }
|
||||
if (bean instanceof FeignBlockingLoadBalancerClient) {
|
||||
FeignBlockingLoadBalancerClient client = (FeignBlockingLoadBalancerClient) bean;
|
||||
return new SeataFeignBlockingLoadBalancerClient(client.getDelegate(),
|
||||
@@ -66,21 +55,4 @@ public class SeataFeignObjectWrapper {
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
// CachingSpringLoadBalancerFactory factory() {
|
||||
// if (this.cachingSpringLoadBalancerFactory == null) {
|
||||
// this.cachingSpringLoadBalancerFactory = this.beanFactory
|
||||
// .getBean(CachingSpringLoadBalancerFactory.class);
|
||||
// }
|
||||
// return this.cachingSpringLoadBalancerFactory;
|
||||
// }
|
||||
|
||||
// SpringClientFactory clientFactory() {
|
||||
// if (this.springClientFactory == null) {
|
||||
// this.springClientFactory = this.beanFactory
|
||||
// .getBean(SpringClientFactory.class);
|
||||
// }
|
||||
// return this.springClientFactory;
|
||||
// }
|
||||
|
||||
}
|
||||
|
@@ -1,38 +0,0 @@
|
||||
///*
|
||||
// * Copyright 2013-2018 the original author or authors.
|
||||
// *
|
||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// * you may not use this file except in compliance with the License.
|
||||
// * You may obtain a copy of the License at
|
||||
// *
|
||||
// * https://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * 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.alibaba.cloud.seata.feign;
|
||||
//
|
||||
//import feign.Feign;
|
||||
//import feign.Retryer;
|
||||
//import feign.hystrix.HystrixFeign;
|
||||
//
|
||||
//import org.springframework.beans.factory.BeanFactory;
|
||||
//
|
||||
///**
|
||||
// * @author xiaojing
|
||||
// */
|
||||
//final class SeataHystrixFeignBuilder {
|
||||
//
|
||||
// private SeataHystrixFeignBuilder() {
|
||||
// }
|
||||
//
|
||||
// static Feign.Builder builder(BeanFactory beanFactory) {
|
||||
// return HystrixFeign.builder().retryer(Retryer.NEVER_RETRY)
|
||||
// .client(new SeataFeignClient(beanFactory));
|
||||
// }
|
||||
//
|
||||
//}
|
@@ -1,45 +0,0 @@
|
||||
///*
|
||||
// * Copyright 2013-2018 the original author or authors.
|
||||
// *
|
||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// * you may not use this file except in compliance with the License.
|
||||
// * You may obtain a copy of the License at
|
||||
// *
|
||||
// * https://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * 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.alibaba.cloud.seata.feign;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//
|
||||
//import feign.Client;
|
||||
//import feign.Request;
|
||||
//import feign.Response;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * @author xiaojing
|
||||
// * @author yuhuangbin
|
||||
// */
|
||||
//public class SeataLoadBalancerFeignClient extends LoadBalancerFeignClient {
|
||||
//
|
||||
// SeataLoadBalancerFeignClient(Client delegate,
|
||||
// CachingSpringLoadBalancerFactory lbClientFactory,
|
||||
// SpringClientFactory clientFactory,
|
||||
// SeataFeignObjectWrapper seataFeignObjectWrapper) {
|
||||
// super((Client) seataFeignObjectWrapper.wrap(delegate), lbClientFactory,
|
||||
// clientFactory);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Response execute(Request request, Request.Options options) throws IOException {
|
||||
// return super.execute(request, options);
|
||||
// }
|
||||
//
|
||||
//}
|
@@ -37,10 +37,8 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.beans.factory.BeanFactory.FACTORY_BEAN_PREFIX;
|
||||
|
||||
/**
|
||||
* {@link Feign.Builder} like {@link HystrixFeign.Builder}.
|
||||
* {@link Feign.Builder}.
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
|
@@ -23,8 +23,6 @@ import java.lang.reflect.Proxy;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
import com.alibaba.csp.sentinel.Entry;
|
||||
import com.alibaba.csp.sentinel.EntryType;
|
||||
import com.alibaba.csp.sentinel.SphU;
|
||||
@@ -36,6 +34,8 @@ import feign.InvocationHandlerFactory.MethodHandler;
|
||||
import feign.MethodMetadata;
|
||||
import feign.Target;
|
||||
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
import static feign.Util.checkNotNull;
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,8 @@ public class SentinelInvocationHandler implements InvocationHandler {
|
||||
if ("equals".equals(method.getName())) {
|
||||
try {
|
||||
Object otherHandler = args.length > 0 && args[0] != null
|
||||
? Proxy.getInvocationHandler(args[0]) : null;
|
||||
? Proxy.getInvocationHandler(args[0])
|
||||
: null;
|
||||
return equals(otherHandler);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
|
Reference in New Issue
Block a user