Spring Cloud 5分钟搭建教程(附上一个分布式日志系统项目作为参考) - 推荐

http://blog.csdn.net/lc0817/article/details/53266212/

 

https://github.com/leoChaoGlut/log-sys

上面是我基于Spring Cloud ,Spring Boot 和 Docker 搭建的一个分布式日志系统.

目前已在我司使用. 想要学习Spring Cloud, Spring Boot以及Spring 全家桶的童鞋,可以参考学习,如果觉得好,star 一下吧~

 

<<<< 20170602 <<<< 

新增Spring Cloud [ Bus, Sleuth, Config, Stream ]教程:

Github: https://github.com/leoChaoGlut/spring-cloud-tutorial

>>>> 20170602 >>>> 

 

<<<< 20170608 <<<< 

Ribbon源码解析及常见问题: http://blog.csdn.net/lc0817/article/details/72886721

>>>> 20170608 >>>> 

1.前言:

1.1.以下内容是我通过阅读官方文档,并成功实践后的经验总结,希望能帮助你更快地理解和使用Spring Cloud. 

1.2.默认读者已经熟练掌握Spring 全家桶,Spring Boot和注解开发.

1.3.陆续更新

 

2.开发环境: @Deprecated

2.1.开发工具:idea

2.2.开发环境:jdk1.7

2.3.Spring版本:

2.3.1.Spring Boot :1.4.0 release

2.3.2.Spring Cloud : Camden SR2

 

3.demo:(献给急于速成的各位大兄弟): demo地址: https://github.com/leoChaoGlut/spring-cloud-demo

3.1.服务注册demo:

3.1.1.创建工程模块,如图所示

3.1.2.将官方提供的maven依赖,加入pom.

[html] view plain copy
 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"  
  3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  5.     <modelVersion>4.0.0</modelVersion>  
  6.   
  7.     <groupId>demo</groupId>  
  8.     <artifactId>spring-cloud-demo</artifactId>  
  9.     <packaging>pom</packaging>  
  10.     <version>1.0-SNAPSHOT</version>  
  11.   
  12.     <modules>  
  13.         <module>discovery</module>  
  14.         <module>service0</module>  
  15.         <module>service1</module>  
  16.     </modules>  
  17.   
  18.     <!--以下dependency来自官方-->  
  19.     <parent>  
  20.         <groupId>org.springframework.boot</groupId>  
  21.         <artifactId>spring-boot-starter-parent</artifactId>  
  22.         <version>1.4.0.RELEASE</version>  
  23.     </parent>  
  24.   
  25.     <dependencyManagement>  
  26.         <dependencies>  
  27.             <dependency>  
  28.                 <groupId>org.springframework.cloud</groupId>  
  29.                 <artifactId>spring-cloud-dependencies</artifactId>  
  30.                 <version>Camden.SR2</version>  
  31.                 <type>pom</type>  
  32.                 <scope>import</scope>  
  33.             </dependency>  
  34.         </dependencies>  
  35.     </dependencyManagement>  
  36.   
  37.     <dependencies>  
  38.         <dependency>  
  39.             <groupId>org.springframework.cloud</groupId>  
  40.             <artifactId>spring-cloud-starter-config</artifactId>  
  41.         </dependency>  
  42.         <dependency>  
  43.             <groupId>org.springframework.cloud</groupId>  
  44.             <artifactId>spring-cloud-starter-eureka</artifactId>  
  45.         </dependency>  
  46.         <dependency>  
  47.             <groupId>org.springframework.boot</groupId>  
  48.             <artifactId>spring-boot-devtools</artifactId>  
  49.             <optional>true</optional>  
  50.         </dependency>  
  51.     </dependencies>  
  52.   
  53.   
  54. </project>  

3.1.3.如图步骤,完成Discovery

 

3.1.4.如图步骤完成Service0,Service1类似

3.1.5.简单到爆炸有没有...........,接下来先启动Discovery,然后启动Service0和Service1

3.1.6.打开浏览器,访问 localhost:8080 ,8080是Discovery里配置的端口号.一切顺利的话,可以看到:

3.1.7.已经成功注册了service0,service1两个服务

3.2.网关demo: 光是注册了服务还不行,这里可以再配一个网关,让服务调用有统一的入口. 

3.2.1.通过上图配置后,首先启动Discovery,其次的服务和网关启动顺序随意.通过访问localhost:8083/service0/service0,即可看到,gateway帮我们转发了请求.

 

3.3.Feign:一个可以把远程服务提供方的 rest 接口变成本地方法调用的Spring Cloud组件

举个栗子:

现在有2个服务,service0, service1

service0提供了一个test接口,

那么这时候,如果service1需要的调用service0,除了通过网关(zuul)调用,还可以使用Feign,来把service0的远程接口,变为本地方法调用.如图:

4.feign + ribbon + hystrix

简介:

hystrix: 以切面为原理,可以在不入侵业务代码的情况下,给方法加上超时等指标,并且可以在超出设置的指标后,调用指定的fallback方法,进行失败回调处理.

ribbon: 客户端负载均衡, 我曾经也写了一个类似的东西(https://github.com/leoChaoGlut/ServiceDIscoveryAndRegistry/tree/master/doc),不过后来发现spring cloud已经有成熟的,现成的常用组件,所以就放弃了.哈哈.... 老式的,无注册中心的服务调用,是通过url来实现的,但是ribbon可以让我们只需要提供服务名,就可以调用到多实例的服务,并且在客户端做一个负载分发,减轻服务端负载的压力.

feign: 给你以Http的形式,带来RPC般的体验.

 

 

认真看图和代码,即可快速上手 feign + ribbon + hystrix 配置

细看spring cloud, feign,ribbon,hystrix的官方文档,加上源码的阅读,即可掌握如何使用spring cloud 配置 这三个组件.

 

5.分布式应用日志追踪: spring cloud sleuth:

http://blog.csdn.net/lc0817/article/details/72829935

6.分布式配置中心: Spring Cloud Config

http://blog.csdn.net/lc0817/article/details/72833007

7.消息总线: Spring Cloud Bus:

http://blog.csdn.net/lc0817/article/details/72836236

8.Netflix 基本组件:Feign Ribbon Hystrix 详细整合

http://blog.csdn.net/lc0817/article/details/72875195

9.流处理:Spring Cloud Stream

http://blog.csdn.net/lc0817/article/details/72956321

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391077.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

51nod1832(二叉树/高精度模板+dfs)

题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId1832 题意: 中文题诶~ 思路: 若二叉树中有 k 个节点只有一个子树, 则答案为 1 << k. 详情参见:http://blog.csdn.net/gyhguoge01234/article/details/77836484 代码: 1 #include <iostream&g…

重学TCP协议(11)TFO(Tcp Fast Open)

1. TFO 为了改善web应用相应时延&#xff0c;google发布了通过修改TCP协议利用三次握手时进行数据交换的TFO(TCP fast open&#xff0c;RFC 7413)。 TFO允许在TCP握手期间发送和接收初始SYN分组中的数据。如果客户端和服务器都支持TFO功能&#xff0c;则可以减少建立到同一服…

[网络安全] 远程登录

远程登录方式: 1.图像化远程登录 做法: 运行"窗口"输入 "mstsc " 输入ip地址 注意: 被远程计算机&#xff0c;必须打开远程登录服务: 信息面板–系统–允许远程访问。被远程计算机&#xff0c;必须存在拥有远程桌面权限的用户。 2.命令行远程登录 teln…

外星人图像和外星人太空船_卫星图像:来自太空的见解

外星人图像和外星人太空船By Christophe Restif & Avi Hoffman, Senior Software Engineers, Crisis Response危机应对高级软件工程师Christophe Restif和Avi Hoffman Editor’s note: In 2019, we piloted a new feature in Search SOS Alerts for major California wild…

chrome恐龙游戏_如何玩没有互联网的Google Chrome恐龙游戏-在线和离线

chrome恐龙游戏Several years ago, Google added a fun little Easter egg to Chrome: if your internet went down and you tried to visit a web page, youd see the message "Unable to connect to the Internet" or "No internet" with a little pixi…

Hotpatch潜在的安全风险

屎蛋 2016/06/22 10:11author:[email protected]0x00 “Hotpatch”简介IOS App的开发者们经常会出现这类问题&#xff1a;当一个新版本上线后发现存在一个严重的bug&#xff0c;有可能因为一个逻辑问题导致支付接口存在被薅羊毛的风险&#xff0c;这个时候能做的只能是赶快修复…

spring中@Inject和@Autowired的区别?分别在什么条件下使用呢?

问题&#xff1a;spring中Inject和Autowired的区别&#xff1f;分别在什么条件下使用呢&#xff1f; 我在浏览SpringSource上的一些博客&#xff0c;在其他一个博客中&#xff0c;那个作者用了Inject&#xff0c;但是我觉得他用Autowired也行 下面是一部分代码&#xff1a; …

Objective-C语言的动态性

Objective-C具有相当多的动态特性&#xff0c;基本的&#xff0c;也是经常被提到和用到的有动态类型&#xff08;Dynamic typing&#xff09;&#xff0c;动态绑定&#xff08;Dynamic binding&#xff09;和动态加载&#xff08;Dynamic loading&#xff09; 一、编译时和运行…

内存泄漏和内存溢出的区别

原文地址https://www.zhihu.com/question/40560123 简单来说&#xff0c;操作系统就像资源分配人员&#xff0c;你要使用内存的时候分给你&#xff0c;你用完了还给它。如果你使用了没有分配给你的内存就是内存溢出&#xff0c;如果你用完了没有还就是内存泄漏。会引起的问题&a…

怎么注销笔记本icloud_如何在笔记本电脑或台式机的Web浏览器中在线查看Apple iCloud照片

怎么注销笔记本icloudPicture this: you just returned from a beautiful vacation and want to show all those gorgeous photos to your family. But your phone just died. And since youre at a family dinner your laptop is nowhere to be found.想象一下&#xff1a;您刚…

棒棒糖 宏_棒棒糖图表

棒棒糖 宏AKA: lollipop plot又名&#xff1a;棒棒糖情节 WHY: a lollipop chart (LC) is a handy variation of a bar chart where the bar is replaced with a line and a dot at the end. Just like bar graphs, lollipop plots are used to make comparisons between diff…

ubuntu上如何安装tomcat

1. 在官网下载linux里面的tomcat 2. 放到DownLoads下面--把tomcat的压缩包放到DownLoads3. sudo mkdir /usr/local/tomcat/ -在usr/local/路径下新建一个tomcat的文件夹4 sudo tar zxvf tomcat。。。。tar.gz -C /usr/local/tomcat/---把解压后的tomcat放到usr/local/下的tomca…

leetcode 1734. 解码异或后的排列(位运算)

给你一个整数数组 perm &#xff0c;它是前 n 个正整数的排列&#xff0c;且 n 是个 奇数 。 它被加密成另一个长度为 n - 1 的整数数组 encoded &#xff0c;满足 encoded[i] perm[i] XOR perm[i 1] 。比方说&#xff0c;如果 perm [1,3,2] &#xff0c;那么 encoded [2,…

ZooKeeper3.4.5-最基本API开发

2019独角兽企业重金招聘Python工程师标准>>> package cn.itcast.bigdata.zk;import java.io.IOException; import java.util.List;import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEven…

字符串转换整数python_将Python字符串转换为Int:如何在Python中将字符串转换为整数

字符串转换整数pythonUnlike many other programming languages out there, Python does not implicitly typecast integers (or floats) to strings when you concatenate them to strings.与现有的许多其他编程语言不同&#xff0c;Python在将整数连接到字符串时不会隐式地将…

理解Java里面的必检异常和非必检异常

问题&#xff1a;理解Java里面的必检异常和非必检异常 Joshua Bloch在"Effective Java"里面说过 在可恢复的条件下和编程错误导致的运行时错误时&#xff0c;使用必检异常&#xff08;第二版的第52页&#xff09; 让我们来看一下我对这个的正确理解吧 下面是我对…

使用vim打开文件的16进制形式,编辑和全文替换

1、先用vim打开文件的二进制形式&#xff0c;如果不以二进制可能会产生转换错误。 vim -b file-to-open.dat 2、用xxd把文件转换成十六进制格式 :%!xxd 现在就可以对待普通文本一样查看和编辑二进制文件了。 3、vim 单文件替换方法 :%s/old/new/gc 全文执行替换,询问是…

nlp自然语言处理_不要被NLP Research淹没

nlp自然语言处理自然语言处理 (Natural Language Processing) 到底是怎么回事&#xff1f; (What is going on?) NLP is the new Computer VisionNLP是新的计算机视觉 With enormous amount go textual datasets available; giants like Google, Microsoft, Facebook etc have…

opencv 随笔

装环境好累&#xff0c;python3.6&#xff0c;opencv3.4 好不容易装好了&#xff0c;结果 addweight的时候总是报错 The operation is neither array op array (where arrays have the same size and the same number of channels), nor array op scalar, nor scalar op array …

js打开飞行模式_什么是飞行模式? 它有什么作用?什么时候应该打开它?

js打开飞行模式If youve flown on an airplane in the last decade and you have a smart phone, youve likely had to put that phone in airplane mode before the plane takes off.如果您在过去的十年中乘坐过飞机&#xff0c;并且拥有一部智能手机&#xff0c;那么您可能必…