LCN基於Spring cloud2.0實現分散式事物管理(一)LCN的修改和部署
阿新 • • 發佈:2018-12-11
首先,對專案進行編譯,裝好maven環境,jdk環境。命令如下,注意這裡需要jdk1.8以上
mvn install -Dmaven.test.skip=true
打包之後,將編譯好的jar包上傳到自己的私服。
獲取最新的tx-manager的jar包,上傳的伺服器上去。啟動相應的jar,我這裡使用的nginx做的叢集部署。
部署說明官方地址:
這裡注意需要修改配置檔案,指定Eureka的註冊地址。
#######################################txmanager-start################################################# #服務埠 server.port=8899 #tx-manager不得修改 spring.application.name=tx-manager spring.mvc.static-path-pattern=/** spring.resources.static-locations=classpath:/static/ #######################################txmanager-end################################################# #zookeeper地址 #spring.cloud.zookeeper.connect-string=127.0.0.1:2181 #spring.cloud.zookeeper.discovery.preferIpAddress = true #eureka 地址 eureka.client.service-url.defaultZone=http://eureka.zhubanxian.com/eureka/ eureka.instance.prefer-ip-address=true #######################################redis-start################################################# #redis 配置檔案,根據情況選擇叢集或者單機模式 ##redis 叢集環境配置 ##redis cluster #spring.redis.cluster.nodes=127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003 #spring.redis.cluster.commandTimeout=5000 ##redis 單點環境配置 #redis #redis主機地址 spring.redis.host=172.17.4.178 #redis主機埠 spring.redis.port=6379 #redis連結密碼 spring.redis.password=zhudaxian;.,68NB spring.redis.pool.maxActive=10 spring.redis.pool.maxWait=-1 spring.redis.pool.maxIdle=5 spring.redis.pool.minIdle=0 spring.redis.timeout=0 #####################################redis-end################################################### #######################################LCN-start################################################# #業務模組與TxManager之間通訊的最大等待時間(單位:秒) #通訊時間是指:發起方與響應方之間完成一次的通訊時間。 #該欄位代表的是Tx-Client模組與TxManager模組之間的最大通訊時間,超過該時間未響應本次請求失敗。 tm.transaction.netty.delaytime = 5 #業務模組與TxManager之間通訊的心跳時間(單位:秒) tm.transaction.netty.hearttime = 15 #儲存到redis下的資料最大儲存時間(單位:秒) #該欄位僅代表的事務模組資料的最大儲存時間,補償資料會永久儲存。 tm.redis.savemaxtime=30 #socket server Socket對外服務埠 #TxManager的LCN協議的埠 tm.socket.port=9999 #最大socket連線數 #TxManager最大允許的建立連線數量 tm.socket.maxconnection=100 #事務自動補償 (true:開啟,false:關閉) # 說明: # 開啟自動補償以後,必須要配置 tm.compensate.notifyUrl 地址,僅當tm.compensate.notifyUrl 在請求補償確認時返回success或者SUCCESS時,才會執行自動補償,否則不會自動補償。 # 關閉自動補償,當出現數據時也會 tm.compensate.notifyUrl 地址。 # 當tm.compensate.notifyUrl 無效時,不影響TxManager執行,僅會影響自動補償。 tm.compensate.auto=true #事務補償記錄回撥地址(rest api 地址,post json格式) #請求補償是在開啟自動補償時才會請求的地址。請求分為兩種:1.補償決策,2.補償結果通知,可通過通過action引數區分compensate為補償請求、notify為補償通知。 #*注意當請求補償決策時,需要補償服務返回"SUCCESS"字串以後才可以執行自動補償。 #請求補償結果通知則只需要接受通知即可。 #請求補償的樣例資料格式: #{"groupId":"TtQxTwJP","action":"compensate","json":"{\"address\":\"133.133.5.100:8081\",\"className\":\"com.example.demo.service.impl.DemoServiceImpl\",\"currentTime\":1511356150413,\"data\":\"C5IBLWNvbS5leGFtcGxlLmRlbW8uc2VydmljZS5pbXBsLkRlbW9TZXJ2aWNlSW1wbAwSBHNhdmUbehBqYXZhLmxhbmcuT2JqZWN0GAAQARwjeg9qYXZhLmxhbmcuQ2xhc3MYABABJCo/cHVibGljIGludCBjb20uZXhhbXBsZS5kZW1vLnNlcnZpY2UuaW1wbC5EZW1vU2VydmljZUltcGwuc2F2ZSgp\",\"groupId\":\"TtQxTwJP\",\"methodStr\":\"public int com.example.demo.service.impl.DemoServiceImpl.save()\",\"model\":\"demo1\",\"state\":0,\"time\":36,\"txGroup\":{\"groupId\":\"TtQxTwJP\",\"hasOver\":1,\"isCompensate\":0,\"list\":[{\"address\":\"133.133.5.100:8899\",\"isCompensate\":0,\"isGroup\":0,\"kid\":\"wnlEJoSl\",\"methodStr\":\"public int com.example.demo.service.impl.DemoServiceImpl.save()\",\"model\":\"demo2\",\"modelIpAddress\":\"133.133.5.100:8082\",\"channelAddress\":\"/133.133.5.100:64153\",\"notify\":1,\"uniqueKey\":\"bc13881a5d2ab2ace89ae5d34d608447\"}],\"nowTime\":0,\"startTime\":1511356150379,\"state\":1},\"uniqueKey\":\"be6eea31e382f1f0878d07cef319e4d7\"}"} #請求補償的返回資料樣例資料格式: #SUCCESS #請求補償結果通知的樣例資料格式: #{"resState":true,"groupId":"TtQxTwJP","action":"notify"} tm.compensate.notifyUrl=http://s3.zhubanxian.com/compernstate?action=notify #補償失敗,再次嘗試間隔(秒),最大嘗試次數3次,當超過3次即為補償失敗,失敗的資料依舊還會存在TxManager下。 tm.compensate.tryTime=30 #各事務模組自動補償的時間上限(毫秒) #指的是模組執行自動超時的最大時間,該最大時間若過段會導致事務機制異常,該時間必須要模組之間通訊的最大超過時間。 #例如,若模組A與模組B,請求超時的最大時間是5秒,則建議改時間至少大於5秒。 tm.compensate.maxWaitTime=5000 #######################################LCN-end################################################# logging.level.com.codingapi=debug
我的修改如上。
使用shell指令碼啟動jar,啟動命令如下:
nohup java -jar -Xms128M -Xmx128M -XX:NewRatio=4 -XX:SurvivorRatio=8 -XX:+PrintGCDateStamps -Xloggc:/data/tx-manager/logs/gc.log -XX:+PrintGCDetails -Xss512K -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=100m -XX:+UseG1GC tx-manager-4.1.2.jar > /data/tx-manager/logs/tx.log 2>&1 &
出現如下介面
說明啟動成功。