mirror of
https://github.com/doocs/advanced-java.git
synced 2025-03-06 09:30:10 +08:00
commit
e95cbf5b54
BIN
docs/micro-services/images/30103116_ZCcM.png
Normal file
BIN
docs/micro-services/images/30103116_ZCcM.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 249 KiB |
BIN
docs/micro-services/images/Before-and-after-migration.png
Normal file
BIN
docs/micro-services/images/Before-and-after-migration.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 95 KiB |
BIN
docs/micro-services/images/Law-of-Holes.png
Normal file
BIN
docs/micro-services/images/Law-of-Holes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 94 KiB |
@ -15,7 +15,7 @@ Martin Fowler 将这种现代化策略成为绞杀(Strangler)应用,名字
|
||||
|
||||
Law of Holes 是说当自己进洞就应该停止挖掘。对于单体式应用不可管理时这是最佳建议。换句话说,应该停止让单体式应用继续变大,也就是说当开发新功能时不应该为旧单体应用添加新代码,最佳方法应该是将新功能开发成独立微服务。如下图所示:
|
||||
|
||||

|
||||

|
||||
|
||||
除了新服务和传统应用,还有两个模块,其一是请求路由器,负责处理入口(http)请求,有点像之前提到的 API 网关。路由器将新功能请求发送给新开发的服务,而将传统请求还发给单体式应用。
|
||||
|
||||
@ -44,7 +44,7 @@ Law of Holes 是说当自己进洞就应该停止挖掘。对于单体式应用
|
||||
3. 数据访问层——访问基础元素,例如数据库和消息代理。
|
||||
|
||||
在表现层与业务数据访问层之间有清晰的隔离。业务层有由若干方面组成的粗粒度(coarse-grained)的 API,内部包含了业务逻辑元素。API 是可以将单体业务分割成两个更小应用的天然边界,其中一个应用是表现层,另外一个是业务和数据访问逻辑。分割后,表现逻辑应用远程调用业务逻辑应用,下图表示迁移前后架构不同:
|
||||

|
||||

|
||||
|
||||
单体应用这么分割有两个好处,其一使得应用两部分开发、部署和扩展各自独立,特别地,允许表现层开发者在用户界面上快速选择,进行 A/B 测试;其二,使得一些远程 API 可以被微服务调用。
|
||||
|
||||
@ -70,7 +70,7 @@ Law of Holes 是说当自己进洞就应该停止挖掘。对于单体式应用
|
||||
|
||||
一旦完成粗粒度接口,也就将此模块转换成独立微服务。为了实现,必须写代码使得单体应用和微服务之间通过使用进程间通信(IPC)机制的 API 来交换信息。如图所示迁移前后对比:
|
||||
|
||||

|
||||

|
||||
|
||||
此例中,正在使用 Y 模块的 Z 模块是备选抽取模块,其元素正在被 X 模块使用,迁移第一步就是定义一套粗粒度 APIs,第一个接口应该是被 X 模块使用的内部接口,用于激活 Z 模块;第二个接口是被 Z 模块使用的外部接口,用于激活 Y 模块。
|
||||
|
||||
|
BIN
images/30103116_ZCcM.png
Normal file
BIN
images/30103116_ZCcM.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 249 KiB |
BIN
images/Before-and-after-migration.png
Normal file
BIN
images/Before-and-after-migration.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 95 KiB |
BIN
images/Law-of-Holes.png
Normal file
BIN
images/Law-of-Holes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 94 KiB |
Loading…
Reference in New Issue
Block a user