spring-cloud

Strategy for unit testing a Spring Cloud Service

有些话、适合烂在心里 提交于 2019-11-29 01:57:51
问题 Given the following Spring Cloud setup: A data-service with access to a database, an eureka-service to handle service registry and discovery and a third service business-service which will be one of various services which encapsulate business cases. Unit testing the data-service is no problem, I just turn off eureka via eureka.client.enabled=false and use an in-memory database for my tests. To access the data-service from business-service , I'm using an @FeignClient("data-service") annotated

@RefreshScope not working - Spring Boot

家住魔仙堡 提交于 2019-11-29 01:15:55
问题 I am following the approach described here: https://github.com/jeroenbellen/blog-manage-and-reload-spring-properties, the only difference is that in my case, the properties are being used in multiple classes so I have put them all in one utility class CloudConfig and I refer to its variables using the getters. This is what the class looks like: @Configuration @RefreshScope public class CloudConfig { static volatile int count; // 20 sec @Value("${config.count}") public void setCount(int count)

Eureka never unregisters a service

时光总嘲笑我的痴心妄想 提交于 2019-11-29 00:25:58
问题 I'm currently facing an issue where Eureka does not unregister a registered service. I've pulled the Eureka server example straight from git hub and made only one change, eureka.enableSelfPreservation = false . My application.yml looks like this: server: port: 8761 eureka: enableSelfPreservation: false client: registerWithEureka: false fetchRegistry: false server: waitTimeInMsWhenSyncEmpty: 0 I've read that if 85% of the registered services stop delivering heartbeats within 15 minutes, Eureka

Feign使用fallbackFactory属性打印fallback异

房东的猫 提交于 2019-11-28 19:46:23
https://cloud.spring.io/spring-cloud-openfeign/reference/html/#spring-cloud-feign-hystrix If one needs access to the cause that made the fallback trigger, one can use the fallbackFactory attribute inside @FeignClient. @FeignClient(name = "microservice-simple-provider-user", fallbackFactory = FeignClientFallbackFactory.class) public interface UserFeignClient { @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET) public User findById(@PathVariable("id") Long id); } @Component public class FeignClientFallbackFactory implements FallbackFactory<UserFeignClient> { private static final

Can a Spring Cloud Feign client share interface with an Spring Web Controller?

99封情书 提交于 2019-11-28 19:43:47
Building an endpoint and client with Spring MVC and Feign Client (with spring cloud). I had the thought that since both ends need to have the same annotations - and that they have to be pretty much in sync. Maybe I could define them in an interface and have the two ends implement that. Testing it out I was somewhat surprised that it actually works for the Spring Web end. But it I cannot find a way to do the same for a Feign client. I basically have the interface: @RequestMapping("/somebaseurl") public interface ServiceInterface { @RequestMapping(value = "/resource/{identifier}", method =

springcloud(十):服务网关zuul

怎甘沉沦 提交于 2019-11-28 19:40:33
前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个微服务框架已经完成了。 我们还是少考虑了一个问题,外部的应用如何来访问内部各种各样的微服务呢?在微服务架构中,后端服务往往不直接开放给调用端,而是通过一个API网关根据请求的url,路由到相应的服务。当添加API网关后,在第三方调用端和服务提供方之间就创建了一面墙,这面墙直接与调用方通信进行权限控制,后将请求均衡分发给后台服务端。 为什么需要API Gateway 1、简化客户端调用复杂度 在微服务架构模式下后端服务的实例数一般是动态的,对于客户端而言很难发现动态改变的服务实例的访问地址信息。因此在基于微服务的项目中为了简化前端的调用逻辑,通常会引入API Gateway作为轻量级网关,同时API Gateway中也会实现相关的认证逻辑从而简化内部服务之间相互调用的复杂度。 2、数据裁剪以及聚合 通常而言不同的客户端对于显示时对于数据的需求是不一致的,比如手机端或者Web端又或者在低延迟的网络环境或者高延迟的网络环境。 因此为了优化客户端的使用体验,API Gateway可以对通用性的响应数据进行裁剪以适应不同客户端的使用需求。同时还可以将多个API调用逻辑进行聚合

Can I configure a @FeignClient url using a properties/yml file?

≯℡__Kan透↙ 提交于 2019-11-28 19:18:48
My goal is to create a strategy of different steps to get from a point-to-point communication between 2 components to a "full blown netflix" style of communication using eureka, ribbon, hystrix. With each iteration I want to add more while I try to limit the amount of changes to the actual code. Feign is my preferred client side framework to make this happen. First step is to create a FeignClient to communicate to the server: @FeignClient(url = "http://localhost:9000") interface Client { @RequestMapping(method = RequestMethod.GET, value = "/author/{author}/addedValue/{addedValue}") Result

Spring OAuth Authorization Server behind Spring Cloud Zuul Proxy

[亡魂溺海] 提交于 2019-11-28 16:00:28
I am currently developing a application based on a micro service architecture. We use a API-Gateway implemented using Spring Cloud Netfix's Zuul Server to route the requests to our micro services. To realize single sign on for all our services I am currently working on an OAuth2 server set up using Spring Cloud Security. The server is basically just copy and past of the implementation in Dave Syer's Repo: https://github.com/dsyer/spring-security-angular/tree/master/oauth2/authserver The main difference is that I want to route the requests to my OAuth server through the Zuul Proxy. This way I

Java使用FeignClient发送HTTP 请求

三世轮回 提交于 2019-11-28 13:51:05
使用FeignClient发送HTTP请求1.添加依赖<!-- spring cloud jar--><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <version>2.1.0.RELEASE</version></dependency><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>2.1.0.RELEASE</version></dependency>2.发送接口 @FeignClient(name = "**ServiceClient", url = "${url.signerUrl}" )public interface **ServiceClient { @RequestMapping(value = "/***", method = RequestMethod.POST) public String ***(@RequestBody(required = true)

微服务SpringCloud之Spring Cloud Config配置中心服务化

江枫思渺然 提交于 2019-11-28 13:44:18
在前面两篇Spring Cloud Config配置中心的博客中都是需要指定配置服务的地址url:spring.cloud.config.uri,客户端都是直接调用配置中心的server端来获取配置文件信息。如果server端要做集群,客户端只能通过原始的方式来路由,server端改变IP地址的时候,客户端也需要修改配置,不符合springcloud服务治理的理念。springcloud提供了这样的解决方案,我们只需要将server端当做一个服务注册到eureka中,client端去eureka中去获取配置中心server端的服务既可。 一、Server端改造 1.添加依赖 在SpringCloudConfigServer项目中,添加spring-cloud-starter-netflix-eureka-client引用。 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> View Code <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM