spring-cloud

Spring cloud 学习(一)

北城以北 提交于 2019-11-30 12:10:24
springcloud(Finchley)+Erueka 实现服务注册发现与负载均衡 准备3个项目,不是模块!!!! spring-cloud-eureka 提供注册于发现服务 spring-cloud-producer 提供者 spring-cloud-comsumer 消费者 ***前言***用idea一个窗口打开多个项目 效果 一个项目运行多个实例run-----Edit configuration 选择要运行多个实例的项目,allow parallel run 打勾 注意!!! (1.启动类的注解不要搞错了,2.我这里的时Finchley版本对应的spring boot 时2.0以上的,其他版本看官方文档,3.在一个idea启动多个producer项目测试负载均衡时,idea会问你是否change class 选择no,不然他会覆盖你之前启动的端口号) spring-cloud-eureka的pom <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org

Spring Cloud 负载均衡初体验

时光总嘲笑我的痴心妄想 提交于 2019-11-30 10:07:24
目录 服务搭建 1.注册中心——Eureka Server 2.服务提供方——Service Provider 3.服务消费方——Service Consumer 服务消费 Feign 与断路器 Hystrix 特别注意 Summary Reference Source Code 本文首发于我的个人博客, Spring Cloud 负载均衡初体验 ,欢迎访问! 使用 Spring Cloud Netflix 组件 Eureka 和 Ribbon 构建单注册中心的负载均衡服务。 Spring Cloud 是基于 Spring 的微服务技术栈,可以这么概括吧,里面包含了很多例如服务发现注册、配置中心、消息总线、负载均衡、断路器、数据监控等组件,可以通过 Spring Boot 的形式进行集成和使用。 目前,项目中有这么个需求,Spring Boot 做一个 web 服务,然后调用 TensorFlow 模型得到结果。但是由于 TensorFlow GPU 版,不支持多线程多引擎,所以只能采用多进程的方式去进行调度,所以需要做一个负载均衡。负载均衡的话,可以分为客户端和服务端负载均衡。我目前还没能领悟到有什么不同,毕竟整体的架构都是一样的,如下如图。其中客户端均衡负载的代表是 Spring Cloud 的 Ribbon,服务端负载均衡代表是 Nginx。 由于项目的压力并不大

Spring Security with OAuth2 and JWT: Encoded password does not look like BCrypt

只谈情不闲聊 提交于 2019-11-30 08:35:49
I am trying to implement a spring AuthorizationServer with JWT. I was able to produce JWT tokens and login until I added BCrypt to the mix. Now, when I am trying to login, I get "Bad credentials" from the API. OAuth2Configuration.java @Configuration @EnableAuthorizationServer public class OAuth2Configuration extends AuthorizationServerConfigurerAdapter { private DataSource dataSource; private AuthenticationManager authenticationManager; private BCryptPasswordEncoder passwordEncoder; public OAuth2Configuration(AuthenticationManager authenticationManager) { this.authenticationManager =

actuator /refresh is not being provided in SpringBoot 2.0.1

被刻印的时光 ゝ 提交于 2019-11-30 07:16:11
问题 I am creating a demo project for Spring-Config-Server and Spring-Config-Client . In SpringBoot 1.5.6.RELEASE everything is working fine. However, when I am upgrading project to 2.0.1.RELEASE it does not provide the actuator endpoints. Actuator endpoint provided in 1.5.6.RELEASE Mapped "{[/refresh || /refresh.json],methods=[POST]}" Mapped "{[/dump || /dump.json],methods=[GET] Mapped "{[/heapdump || /heapdump.json],methods=[GET] Mapped "{[/autoconfig || /autoconfig.json],methods=[GET] Mapped "{

OAuth2ClientContext (spring-security-oauth2) not persisted in Redis when using spring-session and spring-cloud-security

时光怂恿深爱的人放手 提交于 2019-11-30 07:14:33
Thanks a lot in advance for reading this question. Setup I am using: spring-security-oauth2:2.0.7.RELEASE spring-cloud-security:1.0.1.RELEASE spring-session:1.0.1.RELEASE and would have a question regarding the persistence of spring-security-oauth2 OAuth2ClientContext in a Redis datastore when using spring-session (via @EnableRedisHttpSession ) in a Single-Sign-On ( @EnableOAuth2Sso ), reverse proxy ( @EnableZuulProxy ) gateway. Problem It seems to me that the SessionScoped JdkDynamicAopProxied DefaultOAuth2ClientContext created in org.springframework.cloud.security.oauth2.client

springcloud在springboot2.0下的实现笔记-第三篇: 服务消费者(Feign)

家住魔仙堡 提交于 2019-11-30 05:53:12
记录在学习springcloud过程中,在 springboot2.0 环境下实现,所遇到的坑和感悟。 学习的教程: 史上最简单的SpringCloud教程 | 第三篇: 服务消费者(Feign) 一.pom配置 springboot版本为,2.0.6.RELEASE: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> 关键依赖的导入修改为: <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign<

Why is ZUUL forcing a SEMAPHORE isolation to execute its Hystrix commands?

女生的网名这么多〃 提交于 2019-11-30 05:18:38
I noticed Spring-Cloud ZUUL forces the execution isolation to SEMAPHORE instead of the THREAD defaults (as recommended by Netflix). A comment in org.springframework.cloud.netflix.zuul.filters.route.RibbonCommand says: we want to default to semaphore-isolation since this wraps 2 others commands that are already thread isolated But still I don't get it :-( What are those two other commands? Configured this way, Zuul can only sched load but does not allow for timing out and let the client walk away. In short, even if the Hystrix timeout is set to 1000ms, clients will only be released once the

Get failure exception in @HystrixCommand fallback method

爷,独闯天下 提交于 2019-11-30 05:08:20
Is there a way to get the reason a HystrixCommand failed when using the @HystrixCommand annotation within a Spring Boot application? It looks like if you implement your own HystrixCommand , you have access to the getFailedExecutionException but how can you get access to this when using the annotation? I would like to be able to do different things in the fallback method based on the type of exception that occurred. Is this possible? I saw a note about HystrixRequestContext.initializeContext() but the HystrixRequestContext doesn't give you access to anything, is there a different way to use

Strategy for unit testing a Spring Cloud Service

浪尽此生 提交于 2019-11-30 04:34:25
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 interface named DataClient which is @Autowired where needed. The service is discovered by Eureka, if

spring-cloud with ribbon/eureka/hystrix using restTemplate unable to set connect/read timeouts

坚强是说给别人听的谎言 提交于 2019-11-30 04:15:26
问题 I have built a spring boot application using spring-cloud and want to use RestTemplate within my client application (which is also a microservice) so that I can continue using mockMvc for integration testing. I am a using the default ribbon/eureka/hystrix client setup with my client microservice and eureka client within the service I'm calling. This is working (once I figured out that serviceIds are what identifies a service endpoint within restTemplate). My problem is that I cant seem to