spring-cloud

springcloud微服务实战_07_分布式配置

只愿长相守 提交于 2020-02-29 15:09:42
7.1 spring cloud config 简介 spring cloud config 是用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持, 它分为服务端和客户端两部分. 服务端也称为分布式配置中心,它是一个独立的微服务应用,用来连接配置仓库并为客户端提供获取配置信息,加密/解密信息等访问接口. 客户端则是微服务架构中的各个微服务或基础设施,它们通过指定的配置中心来管理应用资源与业务相关的配置内容,并在启动的时候从配置中心获取和加载配置信息. spring cloud config 实现了对服务端和客户端中环境变量和属性配置的抽象映射,所以它除了适用于 spring 构建的应用之外,也可以在任何其他语言运行的应用程序中使用. 由于 spring cloud config 实现的配置中心默认采用 git 来存储配置信息,所以使用 spring cloud config 构建配置服务器,天然就支持对微服务应用配置信息的版本管理, 并且可以通过 git 客户端工具轻松方便的访问与管理配置内容. 快速入门 准备配置仓库 准备一个git仓库,可以在码云或Github上创建都可以。比如本文准备的仓库示例: https://gitee.com/kaisesai/springcloud/config-repo 假设我们读取配置中心的应用名为commonspace

Spring-cloud微服务实战【十】:消息总线Bus

烈酒焚心 提交于 2020-02-29 03:56:03
  回忆一下,在上一篇文章中,我们使用了分布式配置中心config来管理所有微服务的配置文件,那这样有没有什么问题?有,那就是无法配置文件无法自动更新,当我的git服务器上的配置文件更新后,不能同步更新到config-server,需要config-server重启才能生效,这在生产环境下,肯定是不可以的,我们需要当git服务器的文件更新后,自动同步到config-server,并且config-server不需要重启就能获取到最新的配置,因此我们需要借助spring cloud bus消息总线来实现该功能.其实spring cloud bus 本质上是利用MQ(消息中间件,常用的是RabbitMQ或者kafka)实现消息的推送功能. spring cloud bus的使用   上面我们说到spring cloud bus需要借助MQ,本文中我们借助RabbitMQ来实现该功能.首先需要我们在本机安装好RabbitMQ(安装过程就不再说了,大家发挥各自的聪明才智吧~),然后启动RabbitMQ:   以上打印信息说明已经启动好了,让我们登录网页版的控制台看一下,rabbitMQ控制台默认端口号15672:   出现该页面说明rabbitMQ已经成功启动了,大家可以用默认的账号密码guest/guest登录进去看一下:   然后我们将[dhp-micro-service-config

Spring

空扰寡人 提交于 2020-02-26 10:45:14
在 Spring Cloud(一)服务注册与发现 中,我们提供了服务提供者的工程项目,既然有服务的提供方,那么如何去消费所提供的服务,SpringCloud中提供了多种方式来实现,该模块主要就介绍了服务消费,内容包含了服务消费(基础),服务消费(Ribbon),服务消费(Feign)。 服务消费(基础) 创建一个服务消费者工程,命名为: service-consumer ,并在 pom.xml 中引入依赖: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 <parent> <groupId>com.wkedong.springcloud</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version></parent><dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org

Using Eureka as a registry using REST APIs

杀马特。学长 韩版系。学妹 提交于 2020-02-19 12:39:15
问题 We have been using Eureka with our Spring Boot applications for few months now. We have enabled service lookup between applications using @DiscoveryClient annotations. The registrations, lease renewals and deregistration works as expected. Recently, we have encountered a scenario where we have non-Java application component (written in C++), which is exposes 3 REST service endpoints that many of our Spring Boot Java applications would use. We are trying to see if the C++ component can make

Using Eureka as a registry using REST APIs

江枫思渺然 提交于 2020-02-19 12:36:08
问题 We have been using Eureka with our Spring Boot applications for few months now. We have enabled service lookup between applications using @DiscoveryClient annotations. The registrations, lease renewals and deregistration works as expected. Recently, we have encountered a scenario where we have non-Java application component (written in C++), which is exposes 3 REST service endpoints that many of our Spring Boot Java applications would use. We are trying to see if the C++ component can make

Create route in Spring Cloud Gateway with OAuth2 Resource Owner Password grant type

只谈情不闲聊 提交于 2020-02-15 20:12:32
问题 How to configure a route in Spring Cloud Gateway to use an OAuth2 client with authorization-grant-type: password ? In other words, how to add the Authorization header with the token in the requests to an API? Because I'm integrating with a legacy application, I must use the grant type password. I have this application: @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Bean public RouteLocator

Create route in Spring Cloud Gateway with OAuth2 Resource Owner Password grant type

倾然丶 夕夏残阳落幕 提交于 2020-02-15 20:08:15
问题 How to configure a route in Spring Cloud Gateway to use an OAuth2 client with authorization-grant-type: password ? In other words, how to add the Authorization header with the token in the requests to an API? Because I'm integrating with a legacy application, I must use the grant type password. I have this application: @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Bean public RouteLocator

Create route in Spring Cloud Gateway with OAuth2 Resource Owner Password grant type

旧城冷巷雨未停 提交于 2020-02-15 20:05:03
问题 How to configure a route in Spring Cloud Gateway to use an OAuth2 client with authorization-grant-type: password ? In other words, how to add the Authorization header with the token in the requests to an API? Because I'm integrating with a legacy application, I must use the grant type password. I have this application: @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Bean public RouteLocator

Spring-cloud之Eureka服务搭建、集群

人走茶凉 提交于 2020-02-11 00:05:26
eureka是什么? eureka是Netfix的子模块之一也是核心模块,eureka有2个组件,一个eurekaServer(独立的一个微服务),这个服务主要是用来定位服务以实现中间层服务器的负载平衡和故障转移。另外一个是是eurekaClient(我们自己的微服务),是用来与server进行交互的,使服务之间的交互变的非常简单,只需要通过服务标识符即可在server中拿到想要的微服务。 角色关系图: 如何使用? 在spring-cloud项目里面加入依赖: eureka客户端(需要注册的服务pom中添加):   <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency> eureka服务端(eureka独立服务pom中添加): <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency> eureka服务端项目里面加入以下配置: server:  

Spring-Cloud微服务踩坑

*爱你&永不变心* 提交于 2020-02-10 19:54:03
@feignclient和@requestmapping混用的时候出错 重写springmvc扫描controller时不带有@feignclient才实例化 @Configuration @ConditionalOnClass({Feign.class}) public class FeignConfiguration { @Bean public WebMvcRegistrations feignWebRegistrations() { return new WebMvcRegistrationsAdapter() { @Override public RequestMappingHandlerMapping getRequestMappingHandlerMapping() { return new FeignRequestMappingHandlerMapping(); } }; } private static class FeignRequestMappingHandlerMapping extends RequestMappingHandlerMapping { @Override protected boolean isHandler(Class<?> beanType) { return super.isHandler(beanType) &&