目录
1.启动多台 soul-admin
2.启动多台 soul-bootstrap
3.启动多台业务系统
4.验证同步
4.1 负载均衡
4.2 数据同步
修改配置文件,把可以开启允许并行执行的复选框。
application.yml
server: port: 9095 server: port: 9096
启动后状态:
跟上面的一样,修改配置文件,打开并行执行的开关。
application-local.yml
server:
port: 9195server:
port: 9196
使用默认的同步数据策略 websocket,需要配置多个 soul-admin 的地址:
sync: websocket : urls: ws://localhost:9095/websocket,ws://localhost:9096/websocket
启动后状态:
我们使用 examples 中自带的 soul-examples-http,启动两个节点。
修改配置文件 application.yml
server:
port: 8188
address: 0.0.0.0
soul:
http:
adminUrl: http://localhost:9095
port: 8188
contextPath: /http
appName: http
full: falseserver:
port: 8189
address: 0.0.0.0
soul:
http:
adminUrl: http://localhost:9095
port: 8189
contextPath: /http
appName: http
full: false
这里的 adminUrl 配置一个 soul-admin 即可,连接上一个之后,只要能把数据同步过去,其他的节点也都可以通过数据库拿到同步后的数据。
启动后状态:
【插件列表】【divide】【选择器列表】【修改】
2个 soul-bootstrap 节点,配置都一致,默认权重 weight 为50,我们调用几次接口,验证负载均衡。
连续调用6次 http://localhost:9195/http/order/findById?id=95 GET 请求,可以在 soul-bootstrap:9195 console 打印如下日志:
可以看到 "The request urlPath is" 轮流调用 8188 和 8189 两个业务服务节点,因为 weight 都是50,调用比例为 1:1,结果就跟轮询调用一样。
2021-01-31 03:48:06.507 INFO 15860 --- [-work-threads-3] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:48:06.509 INFO 15860 --- [-work-threads-3] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:48:06.510 INFO 15860 --- [-work-threads-3] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 03:48:06.594 ERROR 15860 --- [-work-threads-4] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:48:07.440 INFO 15860 --- [-work-threads-6] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:48:07.440 INFO 15860 --- [-work-threads-6] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:48:07.440 INFO 15860 --- [-work-threads-6] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8188/order/findById?id=95, retryTimes is 0
2021-01-31 03:48:07.493 ERROR 15860 --- [-work-threads-7] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:48:07.759 INFO 15860 --- [-work-threads-9] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:48:07.760 INFO 15860 --- [-work-threads-9] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:48:07.760 INFO 15860 --- [-work-threads-9] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 03:48:07.779 ERROR 15860 --- [work-threads-10] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:48:08.044 INFO 15860 --- [work-threads-12] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:48:08.044 INFO 15860 --- [work-threads-12] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:48:08.045 INFO 15860 --- [work-threads-12] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8188/order/findById?id=95, retryTimes is 0
2021-01-31 03:48:08.072 ERROR 15860 --- [work-threads-13] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:48:08.388 INFO 15860 --- [work-threads-15] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:48:08.388 INFO 15860 --- [work-threads-15] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:48:08.389 INFO 15860 --- [work-threads-15] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 03:48:08.410 ERROR 15860 --- [work-threads-16] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:48:08.744 INFO 15860 --- [work-threads-18] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:48:08.744 INFO 15860 --- [work-threads-18] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:48:08.744 INFO 15860 --- [work-threads-18] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8188/order/findById?id=95, retryTimes is 0
2021-01-31 03:48:08.763 ERROR 15860 --- [work-threads-19] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
我们再连续调用6次 http://localhost:9196/http/order/findById?id=95 GET 请求,可以在 soul-bootstrap:9196 console 打印如下日志:
同样可以看到 "The request urlPath is" 轮流调用 8188 和 8189 两个业务服务节点。
2021-01-31 03:51:50.681 INFO 17340 --- [work-threads-25] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:51:50.686 INFO 17340 --- [work-threads-25] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:51:50.688 INFO 17340 --- [work-threads-25] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8188/order/findById?id=95, retryTimes is 0
2021-01-31 03:51:50.726 ERROR 17340 --- [-work-threads-1] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:51:51.352 INFO 17340 --- [-work-threads-3] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:51:51.352 INFO 17340 --- [-work-threads-3] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:51:51.352 INFO 17340 --- [-work-threads-3] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 03:51:51.375 ERROR 17340 --- [-work-threads-4] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:51:51.595 INFO 17340 --- [-work-threads-6] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:51:51.595 INFO 17340 --- [-work-threads-6] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:51:51.595 INFO 17340 --- [-work-threads-6] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8188/order/findById?id=95, retryTimes is 0
2021-01-31 03:51:51.625 ERROR 17340 --- [-work-threads-7] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:51:51.800 INFO 17340 --- [-work-threads-9] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:51:51.800 INFO 17340 --- [-work-threads-9] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:51:51.800 INFO 17340 --- [-work-threads-9] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 03:51:51.819 ERROR 17340 --- [work-threads-10] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:51:51.996 INFO 17340 --- [work-threads-12] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:51:51.997 INFO 17340 --- [work-threads-12] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:51:51.997 INFO 17340 --- [work-threads-12] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8188/order/findById?id=95, retryTimes is 0
2021-01-31 03:51:52.017 ERROR 17340 --- [work-threads-13] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 03:51:52.210 INFO 17340 --- [work-threads-15] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 03:51:52.210 INFO 17340 --- [work-threads-15] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 03:51:52.211 INFO 17340 --- [work-threads-15] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 03:51:52.232 ERROR 17340 --- [work-threads-16] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
在 9095 修改权重,然后调用接口,查看是否按照修改后的权重发送请求:
8188 weight 30,8189 weight 60。
从日志中可以看到,调用1次8188,就会调用2次8189,符合预期比例 30:60=1:2。
2021-01-31 04:14:58.252 INFO 15860 --- [work-threads-24] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 04:14:58.252 INFO 15860 --- [work-threads-24] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 04:14:58.252 INFO 15860 --- [work-threads-24] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8188/order/findById?id=95, retryTimes is 0
2021-01-31 04:14:58.276 ERROR 15860 --- [work-threads-25] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 04:14:58.543 INFO 15860 --- [-work-threads-1] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 04:14:58.544 INFO 15860 --- [-work-threads-1] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 04:14:58.544 INFO 15860 --- [-work-threads-1] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 04:14:58.574 ERROR 15860 --- [-work-threads-3] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 04:14:59.127 INFO 15860 --- [-work-threads-4] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 04:14:59.127 INFO 15860 --- [-work-threads-4] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 04:14:59.127 INFO 15860 --- [-work-threads-4] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 04:14:59.155 ERROR 15860 --- [-work-threads-6] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 04:14:59.359 INFO 15860 --- [-work-threads-7] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 04:14:59.360 INFO 15860 --- [-work-threads-7] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 04:14:59.360 INFO 15860 --- [-work-threads-7] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8188/order/findById?id=95, retryTimes is 0
2021-01-31 04:14:59.394 ERROR 15860 --- [-work-threads-9] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 04:14:59.559 INFO 15860 --- [work-threads-10] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 04:14:59.559 INFO 15860 --- [work-threads-10] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 04:14:59.559 INFO 15860 --- [work-threads-10] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0
2021-01-31 04:14:59.587 ERROR 15860 --- [work-threads-12] o.d.s.plugin.base.utils.FallbackUtils : can not match selector data: divide
2021-01-31 04:15:14.866 INFO 15860 --- [work-threads-13] o.d.soul.plugin.base.AbstractSoulPlugin : divide selector success match , selector name :/http
2021-01-31 04:15:14.866 INFO 15860 --- [work-threads-13] o.d.soul.plugin.base.AbstractSoulPlugin : divide rule success match , rule name :/http/order/findById
2021-01-31 04:15:14.866 INFO 15860 --- [work-threads-13] o.d.s.plugin.httpclient.WebClientPlugin : The request urlPath is http://10.0.0.2:8189/order/findById?id=95, retryTimes is 0