"Large sites system and Java middleware" study notes (in)

Foreword

Only the head can become strong.

Text has been included to my GitHub repository, welcome Star: https://github.com/ZhongFuCheng3y/3y

Previous review:

This week weekend reading the fourth chapter, now come do some notes, hoping to help you.

Note: Before reading this article, strongly recommended to look at before I wrote an introductory article SpringCloud: layman can understand the SpringCloud, missed the blood loss! . After reading this article and then look back, you will find: This book is about the design and implementation of components support in SpringCloud almost has a corresponding.

Design a service framework

From one we talked about, open the application later, calls between different functions / modules no longer simply via native call, the introduction of service calls remotely .

Service Split

The remote service calls will be difficult to do this stuff? To put it plainly, is no communication between the two servers?

Remote service call

At this time, what can you expect? It must be the Socket bar. Yes, we certainly can complete problem of communication between the two systems by Socket. (Socket I believe we have the time to learn the basis of written Demo, which I will not BB a)

Socket system the communication between the

Socket one or two systems to write nothing, but then we split the application, but the system will become a lot.

The system will become very much

In many cases the system, we write the code on the remote calls might want to consider the following questions:

  1. We certainly do not want every time remote calls are affixed repeat of Socket Code, if the remote method calls like local method call is as simple enough.
  2. A service application in order to achieve high availability, the cluster (multiple machines to deploy the same set of applications). When I call the remote to select which machine call?
  3. 网络之间的传输协议用现成的HTTP呢?还是自定义一套通信协议呢?
  4. 因为我们想调用远程方法像调用本地方法一样,那么在网络上就需要传输Java对象,要传输Java对象,就必须得对其进行序列化和反序列化的处理。能实现序列化的操作也有很多,选择哪一种方式呢?
  5. 网络之间的通讯也有bio、nio、以及aio这几种模式,一般来说我们会选择哪种比较多?如果不了解nio的同学,可以阅读我以前写过的笔记(nio你了解多少?
  6. ….等等等

由于系统之间的调用会非常多,我们自然是不希望写重复的代码的,所以服务框架(也可以说是RPC框架)就应运而生了【说白了就是专门处理远程服务调用的框架】。有了服务框架,我们就可以实现多个系统之间以统一的方式来进行远程调用了。

一个服务框架需要考虑的问题其实远不止上面所列出的那些,比如说:

  • 服务框架与Web应用和Web容器的关系是什么?服务框架和应用是绑定在一起吗?(服务框架作为Web应用的一个依赖包),还是说服务框架只是Web应用的一个扩展(没有和Web应用打包绑定在一起)
  • 服务框架的jar包和Web应用的jar包冲突了怎么办?
  • 为了保证系统的稳定性,流量控制也应该要考虑到
  • 在远程调用的时候,需不需要以更细粒度的方式来进行选择(之前说的是选择哪台机器,但可以细粒度到机器下的接口或者方法)
  • ....等等

二、服务框架的技术实现思路

在书中给出了设计服务框架时需要考虑的问题的同时也给出了一些实现思路,我摘录一些我觉得比较有参考意义的说说。

2.1 像本地一样调用远程服务

比如服务消费方在执行orderService.buy("HHKB键盘")时,实质上调用的是远端的服务

这用到啥技术?明显就是动态代理(给女朋友讲解什么是代理模式

在实现的时候有三个基础属性可以参考一下:

  • interfaceName— 确定调用的是哪一个接口
  • version— 如果接口进行升级了,可以使用version来进行区分和隔离
  • group— 对远程服务的机器进行分组,那么调用的时候就可以选择不同的分组来调用(调用者对统一服务的调用进行隔离)

2.2 其他

  1. 当远程调用服务的时候,不需要每次都要去注册中心查找可用的地址,而是把地址缓存在调用方。当服务有变化的时候,主动告诉调用者就行了。
  2. 流量控制一般会基于两个维度去考虑:一、自身的接口和方法。二、请求的来源
  3. 并不是所有的请求都要经过服务提供者。像走缓存这样频繁的操作(而且大多数都是会成功的),直接在调用方调用就ok了

Go directly to the caller cache

最后

总的来说,书的第四章主要是在讲解在设计服务框架的时候应该要考虑到哪些方面,可以以什么方案来解决,看得还是非常过瘾的(这只是我的个人笔记,书上还有很多的内容)。强烈建议配合我之前写过的一篇SpringCloud入门文章:外行人都能看懂的SpringCloud,错过了血亏!食用。

乐于输出干货的Java技术公众号:Java3y。公众号内有200多篇原创技术文章、海量视频资源、精美脑图,关注即可获取!

Forwarded to the circle of friends is the biggest support for me!

I think the article is well written, points praise !

Guess you like

Origin www.cnblogs.com/Java3y/p/11117205.html