什么是微服务?有什么好处坏处?原理是什么?
what is microservice?
it is actually an architectural style that structures an application as a collection of small services.
(it is architecture without any coding)
what’s the advantages of micro services?
- a big project can be divided into serveral smaller services so we can develop and deploy independently.(low coupling)
- also, if we want to do scalling, instead of scalling on all the components, we can only scalling one service as we needed.
- independent can also brings up “one services failed won’t effect others” --isolation
MicroService架构
MicroService代码架构实例
可以看出来 上面有三个service
cal discovery twosum_main
为什么 从哪里看出来的?从config_server 这个服务就是储存所有服务的配置的server.
展开一下
两个cal的配置 一个discovery 一个main的配置。
为什么两个cal? 这是两个服务 只是property不一样 代码都是一样的 我们要是都想把这两个服务启动 就需要去到:
active: dev启动一次 然后改成dev2启动一次。
如何启动这个cal服务(或者说所有的服务),见cal的例子:
启动此文件中的main函数就行了。
然后另外一个twoSum_main的service也是一个普通的service.
最后一个service_discovery这个service 比较特殊 他是用来注册管理所有的service的 比如说如果A服务想连接B服务 就需要A先找discovery service查找B服务(按照注册服务的名字)来找IP地址。
这种模式非常好 好处在哪里呢?首先就是便于管理 每次我们加上一个服务 直接注册就行了 其他服务需要 就直接找。如果一个服务炸了 而没有通知 如果直接就连 那么肯定会失败。有了这个管理器 就会管理这些down掉的服务 暂时清除等等。
最后一个是zipkin_log服务 这个服务其实是日志管理打印功能。