spring-cloud

分布式配置中心客户端

放肆的年华 提交于 2019-12-05 10:01:42
概述 创建一个工程名为 hello-spring-cloud-config-client 的项目, pom.xml 文件配置如下: <?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/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.snake</groupId> <artifactId>hello-spring-cloud-dependencies</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../hello-spring-cloud-dependencies/pom.xml</relativePath> </parent> <artifactId>hello-spring-cloud-config-client

使用路由网关统一访问接口

你离开我真会死。 提交于 2019-12-05 10:00:19
概述 在微服务架构中,需要几个基础的服务治理组件,包括服务注册与发现、服务消费、负载均衡、熔断器、智能路由、配置管理等,由这几个基础组件相互协作,共同组建了一个简单的微服务系统。一个简单的微服务系统如下图: 在 Spring Cloud 微服务系统中,一种常见的负载均衡方式是,客户端的请求首先经过负载均衡(Zuul、Ngnix),再到达服务网关(Zuul 集群),然后再到具体的服。服务统一注册到高可用的服务注册中心集群,服务的所有的配置文件由配置服务管理,配置服务的配置文件放在 GIT 仓库,方便开发人员随时改配置。 # Zuul 简介 Zuul 的主要功能是路由转发和过滤器。路由功能是微服务的一部分,比如 /api/user 转发到到 User 服务, /api/shop 转发到到 Shop 服务。Zuul 默认和 Ribbon 结合实现了负载均衡的功能。 # 创建路由网关 pom.xml 文件如下: <?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/POM

创建服务消费者(Ribbon)

前提是你 提交于 2019-12-05 08:53:45
概述 在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于 http restful 的。Spring cloud 有两种服务调用方式,一种是 ribbon + restTemplate,另一种是 feign。在这一篇文章首先讲解下基于 ribbon + rest。 # Ribbon 简介 Ribbon 是一个负载均衡客户端,可以很好的控制 http 和 tcp 的一些行为。 # 准备工作 启动服务提供者(本教程案例工程为: hello-spring-cloud-service-admin ),端口号为: 8762 修改配置文件的端口号为: 8763 ,启动后在 Eureka 中会注册两个实例,这相当于一个小集群 # 创建服务消费者 创建一个工程名为 hello-spring-cloud-web-admin-ribbon 的服务消费者项目, pom.xml 配置如下: <?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/POM/4.0.0

SpringCloud之Ribbon负载均衡及Feign消费者调用服务

孤人 提交于 2019-12-05 07:12:59
目的:      微服务调用 Ribbon      Ribbon负载均衡      Feign简介及应用 微服务调用Ribbon    Ribbon简介    1. 负载均衡框架,支持可插拔式的负载均衡规则   2. 支持多种协议,如HTTP、UDP等   3. 提供负载均衡客户端 Ribbon是Netflix发布的负载均衡器,它有助于控制HTTP和TCP的客户端的行为。为Ribbon配置服务提供者地址后,Ribbon就可基于某种负载均衡算法,自动地帮助服务消费者去请求。Ribbon默认为我们提供了很多负载均衡算法,例如轮询、随机等。当然,我们也可为Ribbon实现自定义的负载均衡算法。 在Spring Cloud中,当Ribbon与Eureka配合使用时,Ribbon可自动从Eureka Server获取服务提供者地址列表,并基于负载均衡算法,请求其中一个服务提供者实例。展示了Ribbon与Eureka配合使用时的架构。 初步应用 Ribbon是客户端负载均衡,所以肯定集成再消费端,也就是consumer端 我们修改 microservice-student-consumer-80 (工程我是在上一篇博客中玩集成建成 https://www.cnblogs.com/huangting/p/11902121.html ) 首先,引入依赖, pom.xml 加入

USERAUTH fail with private key file for Github and Spring cloud config

我与影子孤独终老i 提交于 2019-12-05 06:09:57
I tried to use the method for using private key (that has passphrase and is added to ssh-agent from file) (according to this stack post): spring: cloud: config: server: git: uri: git@github.com-forApp:myorg/myrepo.git search-paths: '{application}' clone-on-start: true private_key_file: ~/.ssh/id_rsa but I keep getting org.eclipse.jgit.api.errors.TransportException: git@github.com:myorg/myrepo.git: USERAUTH fail Do I have to do it exactly as doc says with pasting the key into config file or can one just point to the key file somehow? EDIT Actually it turns out that the private_key_file is not

SpringBoot @SqsListener - not working - with Exception - TaskRejectedException

可紊 提交于 2019-12-05 05:47:16
I have a AWS SQS with 5000 messages already on the Queue (Sample Message looks like this 'Hello @ 1') I created a SpringBoot Application and inside one of the Component Classes create a method to read messages from the SQS. package com.example.aws.sqs.service; import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy; import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener; import org.springframework.stereotype.Component; import lombok.extern.slf4j.Slf4j; @Component @Slf4j public class MessageReceiverService { @SqsListener(value = { "${cloud.aws

springcould03 (微服务调用Ribbon、Feign简介及应用)

会有一股神秘感。 提交于 2019-12-05 04:59:00
微服务调用Ribbon 简介 前面讲了eureka服务注册与发现,但是结合eureka集群的服务调用没讲。 这里的话 就要用到Ribbon,结合eureka,来实现服务的调用; Ribbon是Netflix发布的负载均衡器,它有助于控制HTTP和TCP的客户端的行为。为Ribbon配置服务提供者地址后,Ribbon就可基于某种负载均衡算法,自动地帮助服务消费者去请求。Ribbon默认为我们提供了很多负载均衡算法,例如轮询、随机等。当然,我们也可为Ribbon实现自定义的负载均衡算法。 在Spring Cloud中,当Ribbon与Eureka配合使用时,Ribbon可自动从Eureka Server获取服务提供者地址列表,并基于负载均衡算法,请求其中一个服务提供者实例。展示了Ribbon与Eureka配合使用时的架构。 Ribbon是客户端负载均衡,所以肯定集成再消费端,也就是consumer端 我们修改 microservice-student-consumer-80 首先,引入依赖,pom.xml 加入 ribbon相关依赖 <!--ribbon相关依赖--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId>

Feign client and Spring retry

[亡魂溺海] 提交于 2019-12-05 04:42:05
I have a restful service calling an external service using Spring Cloud Feign client @FeignClient(name = "external-service", configuration = FeignClientConfig.class) public interface ServiceClient { @RequestMapping(value = "/test/payments", method = RequestMethod.POST) public void addPayment(@Valid @RequestBody AddPaymentRequest addPaymentRequest); @RequestMapping(value = "/test/payments/{paymentId}", method = RequestMethod.PUT) public ChangePaymentStatusResponse updatePaymentStatus(@PathVariable("paymentId") String paymentId, @Valid @RequestBody PaymentStatusUpdateRequest

Netflix Eureka and 2 instances of application on local environment

倖福魔咒の 提交于 2019-12-05 03:52:54
问题 I'm getting started with Netflix Eureka and using its 1.1.145 (https://github.com/Netflix/eureka/tree/1.1.145) version. I want to start locally 2 instances of the same application on different ports and have them both registered with Eureka. I'm using sample service (https://github.com/Netflix/eureka/blob/1.1.145/eureka-server/conf/sampleservice/sample-eureka-service.properties) So I start Eureka itself and 2 instances using above config - one app on 8001 port and another on 8002. For some

Simple Gateway Using Spring Cloud Gateway - ProxyExchange

心已入冬 提交于 2019-12-05 02:59:30
问题 I wanted to write a simple gateway using spring cloud, so that requests to a third party would appear to come from my service (as I have done so in the past with Zuul). The example on the github page and likewise in the official docs seems to be exactly what I want. i.e. a simple controller route to proxy all requests to a given route: @GetMapping("/proxy/path/**") public ResponseEntity<?> proxyPath(ProxyExchange<?> proxy) throws Exception { String path = proxy.path("/proxy/path/"); return