前言
上回說到阻荒, 同步數(shù)據(jù)有不同的策略崔涂。如果一個 admin 配置多個同步方式那么 soul-web 會選哪個呢罗珍?還是一個 admin 只能配置一個同步策略呢邢享?
配置多個同步策略
配置多個同步策略時鹏往,需要 zookeeper 和 nacos 兩個服務(wù)。這里使用 docker 安裝即可骇塘。詳情點擊: zookeeper docker 安裝伊履, nacaos 安裝,根據(jù)提示檢測是否成功款违。
成功后我們 soul-admin 后臺配置唐瀑。
soul:
sync:
websocket:
enabled: true
zookeeper:
url: localhost:2181
sessionTimeout: 5000
connectionTimeout: 2000
http:
enabled: true
nacos:
url: localhost:8848
namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
acm:
enabled: false
endpoint: acm.aliyun.com
namespace:
accessKey:
secretKey:
重新啟動 admin, 將 soul-bootstrap 修改如下
soul :
sync:
websocket :
urls: ws://localhost:9095/websocket
zookeeper:
url: localhost:2181
sessionTimeout: 5000
connectionTimeout: 2000
# 這里先注釋掉插爹,bootstrap http 和 webscoket 會報錯哄辣,下面會解釋原因
# http:
# url : http://localhost:9095
nacos:
url: localhost:8848
namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
acm:
enabled: false
endpoint: acm.aliyun.com
namespace:
accessKey:
secretKey:
然后檢查 pom 文件相關(guān)包是否引入:
<!--soul data sync start use zookeeper-->
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-sync-data-zookeeper</artifactId>
<version>${project.version}</version>
</dependency>
<!--soul data sync start use websocket-->
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-sync-data-websocket</artifactId>
<version>${project.version}</version>
</dependency>
<!--soul data sync start use http-->
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-sync-data-http</artifactId>
<version>${project.version}</version>
</dependency>
<!-- soul data sync start use nacos-->
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-sync-data-http</artifactId>
<version>${project.version}</version>
</dependency>
沒有引入的話,自行引入即可赠尾,重新啟動 bootstrap力穗。從命令行看出
2021-01-21 18:59:34.263 INFO 6334 --- [ main] s.b.s.d.z.ZookeeperSyncDataConfiguration : you use zookeeper sync soul data.......
...
2021-01-21 18:59:34.395 INFO 6334 --- [ main] b.s.s.d.w.WebsocketSyncDataConfiguration : you use websocket sync soul data.......
2021-01-21 18:59:34.441 INFO 6334 --- [ main] d.s.s.s.s.d.n.NacosSyncDataConfiguration : you use nacos sync soul data.......
2021-01-21 18:59:34.851 WARN 6334 --- [ main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nacosSyncDataService' defined in class path resource [org/dromara/soul/springboot/starter/sync/data/nacos/NacosSyncDataConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.dromara.soul.sync.data.api.SyncDataService]: Factory method 'nacosSyncDataService' threw exception; nested exception is java.lang.NullPointerException
2021-01-21 18:59:34.853 INFO 6334 --- [-localhost:2181] org.I0Itec.zkclient.ZkEventThread : Terminate ZkClient event thread.
2021-01-21 18:59:34.970 INFO 6334 --- [ main] org.apache.zookeeper.ZooKeeper : Session: 0x10001d80adf0007 closed
2021-01-21 18:59:34.970 INFO 6334 --- [ain-EventThread] org.apache.zookeeper.ClientCnxn : EventThread shut down for session: 0x10001d80adf0007
2021-01-21 18:59:34.982 INFO 6334 --- [ main] ConditionEvaluationReportLoggingListener :
Debug
判斷是否是 nacos 的配置有誤。按照上述流程气嫁,注釋掉其他的策略当窗,只留 nacos,配置好重啟寸宵。
發(fā)現(xiàn)還是報錯, 經(jīng)過調(diào)試發(fā)現(xiàn):
configInfo
現(xiàn)在在 soul 上提了一個 issue 崖面,有可能是個bug,但也有可能是我配置 nacos 的問題梯影。
解決辦法
- 確保是否是 Nacos 的配置問題巫员。
-
登錄 admin 后臺,在以下菜單上配置好信息光酣,然后同步到 nacos 上疏遏,
需要同步數(shù)據(jù)的菜單
看看 nacos 上是否有信息。
配置權(quán)限的時候救军,需要在列表處,打上勾倘零,不然會無法傳輸
權(quán)限配置 -
檢查 nacos 是否都有以下參數(shù)
nacos 檢查 - 啟動 soul 網(wǎng)關(guān), 出現(xiàn)以下則配置成功
2021-01-22 09:55:36.837 INFO 8210 --- [ main] d.s.s.s.s.d.n.NacosSyncDataConfiguration : you use nacos sync soul data.......
2021-01-22 09:55:37.197 INFO 8210 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2021-01-22 09:55:37.756 INFO 8210 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 9195
2021-01-22 09:55:37.760 INFO 8210 --- [ main] o.d.s.b.SoulBootstrapApplication : Started SoulBootstrapApplication in 3.625 seconds
總結(jié)
- 調(diào)試的時候唱遭,如果發(fā)現(xiàn)問題,可以先把身邊用過的人問問是否會出現(xiàn)這種情況呈驶,是個例還是通性問題拷泽。
- 如果是通性問題,可以去社區(qū),或者 github 上直接提 issue 問清楚司致。不要害怕寫英語拆吆,其實大家水平都差不多。