感觉微服务都差不多概念,最近稍微看了下springcloud,感觉入门还是很简单的,框架用用就那么回事,深入的话需要很多时间投入了

学一个东西,我推荐首先从概念上了解到他是做什么的,什么时候需要,基本模块是什么,然后可以自己写一些小的例子,后续根据需要深入到探寻源码

某位热心同学写的入门例子,我下载学习了下:http://git.oschina.net/zhou666/spring-cloud-7simple

集成了了Netfix的一些关键组件:

服务发现——Netflix Eureka

客服端负载均衡——Netflix Ribbon

断路器——Netflix Hystrix

服务网关——Netflix Zuul

分布式配置——Spring Cloud Config

Eureka服务发现,启动后可以在控制台看到其他配置了该eureka地址的服务

application.properties中定义eureka服务相关信息

server.port=1111
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
spring.application.name=cloud-eureka-server
manager url:http://localhost:1111/

spring-boot 注解方式启动服务

@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
public static void main(String[] args) {
SpringApplication.run(EurekaServer.class, args);
}
}

打开控制台可以看到eureka服务已经启动成功

启动两个server2222/2223,在配置中制定eureka的服务地址

spring.application.name=ribbon-consumer
server.port=2222
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
@EnableDiscoveryClient
@SpringBootApplication
public class ComputeServiceApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ComputeServiceApplication.class).web(true).run(args);
}
}

启动后可以看到eureka控制台有这两个服务出现

修改端口为3333

启动ribbon轮询负载均衡器:

@SpringBootApplication
@EnableDiscoveryClient
public class RibbonApplication {
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(RibbonApplication.class, args);
}
}

可以看到eureka可以发现该服务,并且访问http://localhost:3333/add?a=1&b=2时,后台分别传递给了2222和2223实现了负载均衡调度

Hystrix熔断机制:

application.yml

server:
port: 8989 spring:
application:
name: turbine
cloud:
config:
enabled: true
uri: http://localhost:8888
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:1111/eureka/ turbine:
aggregator:
clusterConfig: CLOUD-SIMPLE-UI
appConfig: cloud-simple-ui
clusterNameExpression: metadata['cluster']
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableTurbine
public class TurbineApplication { public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}

Config配置管理:

server.port=8888
spring.cloud.config.server.git.uri=https://git.oschina.net/zhou666/spring-cloud-7simple.git
spring.cloud.config.server.git.searchPaths=cloud-config-repo
eureka.client.serviceUrl.defaultZone=http\://localhost\:1111/eureka/
spring.application.name=cloud-config-server
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}

zuul服务网关,类似Nginx反向代理服务器,配置各种Ip过来给哪个下级处理

logging:
level.org.springframework.cloud: DEBUG
server:
port: 8080
zuul:
ignoredPatterns: /health,/error
retryable: true
routes:
smarts:
stripPrefix: true
path: /smart/**
serviceId: smarts
ribbon:
eureka:
enabled: false
smarts:
ribbon:
listOfServers: localhost:2222,localhost:2223

定义映射规则,当访问http://localhost:8080/smart/add?a=1&b=2会按照规则/smart/**将请求定位到2222/2223

@EnableZuulProxy
@SpringBootApplication
public class ZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication.class, args);
}
}

微服务-springcloud的更多相关文章

  1. 微服务SpringCloud之配置中心和消息总线

    在微服务SpringCloud之Spring Cloud Config配置中心SVN博客中每个client刷新配置信息时需要post请求/actuator/refresh,但客户端越来越多时,,需要每 ...

  2. Java生鲜电商平台-深入理解微服务SpringCloud各个组件的关联与架构

    Java生鲜电商平台-深入理解微服务SpringCloud各个组件的关联与架构 概述 毫无疑问,Spring Cloud是目前微服务架构领域的翘楚,无数的书籍博客都在讲解这个技术.不过大多数讲解还停留 ...

  3. 小D课堂 - 新版本微服务springcloud+Docker教程_汇总

    小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介 小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型 小D课堂 - 新版本微服务s ...

  4. 「 从0到1学习微服务SpringCloud 」10 服务网关Zuul

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config 「 从0到1学习微服务SpringCloud 」07 RabbitM ...

  5. 「 从0到1学习微服务SpringCloud 」09 补充篇-maven父子模块项目

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config 「 从0到1学习微服务SpringCloud 」07 RabbitM ...

  6. 「 从0到1学习微服务SpringCloud 」08 构建消息驱动微服务的框架 Spring Cloud Stream

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...

  7. 「 从0到1学习微服务SpringCloud 」07 RabbitMq的基本使用

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...

  8. 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...

  9. 「 从0到1学习微服务SpringCloud 」05服务消费者Fegin

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...

  10. 「 从0到1学习微服务SpringCloud 」04服务消费者Ribbon+RestTemplate

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...

随机推荐

  1. MySQL数据库InnoDB存储引擎中的锁机制(转载)

    http://www.uml.org.cn/sjjm/201205302.asp 00 – 基本概念 当并发事务同时访问一个资源的时候,有可能导致数据不一致.因此需要一种致机制来将访问顺序化. 锁就是 ...

  2. vultr上 windows使用pptp拨号来实现冗余双网关的解决方案

    rasdial是拨号程序,pptpvpn是网卡拨号名称,后面跟的是帐号和密码.pptpvpn见下图:就是提前创建好一个PPTP的拨号连接 上面是启动时候的计划任务,那么万一拨号中断,要继续重拨还需要做 ...

  3. NPF or NPCAP service is not installed

    "NPF or NPCAP service is not installed" "could not start local server process:GNS3&qu ...

  4. [UE4]世界坐标、本地坐标

    本地坐标 世界坐标

  5. vue todolist 封装localstorage

    //封装操作localstorage本地存储的方法 模块化的文件 // nodejs 基础 var storage={ set(key,value){ localStorage.setItem(key ...

  6. 第11课 std::bind和std::function(2)_std::bind绑定器

    1. 温故知新:std::bind1st和std::bind2nd (1)bind1st.bind2nd首先它们都是函数模板,用于将参数绑定到可调用对象(如函数.仿函数等)的第1个或第2个参数上. ( ...

  7. python多进程与服务器并发

    进程 什么是进程 进程:正在进行的一个过程或者说一个任务.而负责执行任务则是cpu. 进程与程序的区别 程序仅仅只是一堆代码而已,而进程指的是程序的运行过程. 并发与并行 无论是并行还是并发,在用户看 ...

  8. 1-hadoop安装、ssh、节点退役与服役

    1.准备 四台虚拟机 ①卸载openjdk ②安装jdk 2. 配置静态ip: ip : 每个机器在internet上的唯一标识 子网掩码: 必须结合IP地址一起使用,将某个IP地址划分成网络地址和主 ...

  9. day10学习笔记整理

    函数对象函数是第一类对象: 指的是函数名指向的值(函数)可以被当作数据去使用 1. 可以被引用 2. 可以当作参数传给另外一个函数 3. 可以当作一个函数的返回值 4. 可以当作容器类型的元素   l ...

  10. Element-UI安装和项目开发

          方法一:引入CDN 使用起来最简单的方法,直接引入CDN就可以工作了 <!-- 引入样式 --> <link rel="stylesheet" hre ...