欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringCloud分布式事務(wù)Seata部署和集成過(guò)程

 更新時(shí)間:2023年10月20日 15:07:32   作者:Mr.D.Chuang  
這篇文章主要介紹了SpringCloud分布式事務(wù)Seata部署和集成過(guò)程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

一、部署Seata的tc-server

1.下載

首先我們要下載seata-server包,地址在http://seata.io/zh-cn/blog/download.html

2.解壓

在非中文目錄解壓縮這個(gè)zip包,其目錄結(jié)構(gòu)如下:

3.修改配置

修改conf目錄下的registry.conf文件:

內(nèi)容如下:

#  Copyright 1999-2019 Seata.io Group.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

server:
  port: 7091

spring:
  application:
    name: seata-server

logging:
  config: classpath:logback-spring.xml
  file:
    path: ${user.home}/logs/seata
  extend:
    logstash-appender:
      destination: 127.0.0.1:4560
    kafka-appender:
      bootstrap-servers: 127.0.0.1:9092
      topic: logback_to_logstash

console:
  user:
    username: seata
    password: seata

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: file
    nacos:
      server-addr: 124.222.106.122:8848
      namespace: f4d6567e-1d68-476e-bcf5-9c08b34a605e
      group: DEFAULT_GROUP
      username: nacos
      password: nacos
      #context-path:
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key:
      #secret-key:
      data-id: seataServer.properties
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: file
    nacos:
      application: seata-server
      server-addr: 124.222.106.122:8848
      group: DEFAULT_GROUP
      namespace: f4d6567e-1d68-476e-bcf5-9c08b34a605e
      cluster: SH
      username: nacos
      password: nacos
      #context-path:
      ##if use MSE Nacos with auth, mutex with username/password attribute
      #access-key:
      #secret-key:    
  store:
    # support: file 、 db 、 redis
    mode: file
#  server:
#    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  security:
    secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    tokenValidityInMilliseconds: 1800000
    ignore:
      urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

4.在nacos添加配置

特別注意,為了讓tc服務(wù)的集群可以共享配置,我們選擇了nacos作為統(tǒng)一配置中心。因此服務(wù)端配置文件seataServer.properties文件需要在nacos中配好。

格式如下:

配置內(nèi)容如下:

# 數(shù)據(jù)存儲(chǔ)方式,db代表數(shù)據(jù)庫(kù)
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=123456
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
# 事務(wù)、日志等配置
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000

# 客戶端與服務(wù)端傳輸方式
transport.serialization=seata
transport.compressor=none
# 關(guān)閉metrics功能,提高性能
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

其中的數(shù)據(jù)庫(kù)地址、用戶名、密碼都需要修改成你自己的數(shù)據(jù)庫(kù)信息。

5.創(chuàng)建數(shù)據(jù)庫(kù)表

特別注意:tc服務(wù)在管理分布式事務(wù)時(shí),需要記錄事務(wù)相關(guān)數(shù)據(jù)到數(shù)據(jù)庫(kù)中,你需要提前創(chuàng)建好這些表。

新建一個(gè)名為seata的數(shù)據(jù)庫(kù),運(yùn)行sql文件,這些表主要記錄全局事務(wù)、分支事務(wù)、全局鎖信息:

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- 分支事務(wù)表
-- ----------------------------
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table`  (
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `transaction_id` bigint(20) NULL DEFAULT NULL,
  `resource_group_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `resource_id` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `branch_type` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `status` tinyint(4) NULL DEFAULT NULL,
  `client_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gmt_create` datetime(6) NULL DEFAULT NULL,
  `gmt_modified` datetime(6) NULL DEFAULT NULL,
  PRIMARY KEY (`branch_id`) USING BTREE,
  INDEX `idx_xid`(`xid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- 全局事務(wù)表
-- ----------------------------
DROP TABLE IF EXISTS `global_table`;
CREATE TABLE `global_table`  (
  `xid` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `transaction_id` bigint(20) NULL DEFAULT NULL,
  `status` tinyint(4) NOT NULL,
  `application_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `transaction_service_group` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `transaction_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `timeout` int(11) NULL DEFAULT NULL,
  `begin_time` bigint(20) NULL DEFAULT NULL,
  `application_data` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gmt_create` datetime NULL DEFAULT NULL,
  `gmt_modified` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`xid`) USING BTREE,
  INDEX `idx_gmt_modified_status`(`gmt_modified`, `status`) USING BTREE,
  INDEX `idx_transaction_id`(`transaction_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
SET FOREIGN_KEY_CHECKS = 1;

6.啟動(dòng)TC服務(wù)

進(jìn)入bin目錄,運(yùn)行其中的seata-server.bat即可:

啟動(dòng)成功后,seata-server應(yīng)該已經(jīng)注冊(cè)到nacos注冊(cè)中心了。

打開(kāi)瀏覽器,訪問(wèn)nacos地址:http://localhost:8848,然后進(jìn)入服務(wù)列表頁(yè)面,可以看到seata-tc-server的信息:

二、微服務(wù)集成seata

1.引入依賴

首先,我們需要在微服務(wù)中引入seata依賴:

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
    <exclusions>
        <!--版本較低,1.3.0,因此排除-->
        <exclusion>
            <artifactId>seata-spring-boot-starter</artifactId>
            <groupId>io.seata</groupId>
        </exclusion>
    </exclusions>
</dependency>
<!--seata starter 采用1.4.2版本-->
<dependency>
    <groupId>io.seata</groupId>
    <artifactId>seata-spring-boot-starter</artifactId>
    <version>${seata.version}</version>
</dependency>

2.修改配置文件

需要修改application.yml文件,添加一些配置:

seata:
  registry: # TC服務(wù)注冊(cè)中心的配置,微服務(wù)根據(jù)這些信息去注冊(cè)中心獲取tc服務(wù)地址
    # 參考tc服務(wù)自己的registry.conf中的配置
    type: nacos
    nacos: # tc
      server-addr: 127.0.0.1:8848
      namespace: ""
      group: DEFAULT_GROUP
      application: seata-tc-server # tc服務(wù)在nacos中的服務(wù)名稱
      cluster: SH
  tx-service-group: seata-demo # 事務(wù)組,根據(jù)這個(gè)獲取tc服務(wù)的cluster名稱
  service:
    vgroup-mapping: # 事務(wù)組與TC服務(wù)cluster的映射關(guān)系
      seata-demo: SH

三、TC服務(wù)的高可用和異地容災(zāi)

1.模擬異地容災(zāi)的TC集群

計(jì)劃啟動(dòng)兩臺(tái)seatatc服務(wù)節(jié)點(diǎn):

節(jié)點(diǎn)名稱ip地址端口號(hào)集群名稱
seata127.0.0.18091SH
seata2127.0.0.18092HZ

之前我們已經(jīng)啟動(dòng)了一臺(tái)seata服務(wù),端口是8091,集群名為SH

現(xiàn)在,將seata目錄復(fù)制一份,起名為seata2

修改seata2/conf/registry.conf內(nèi)容如下:

registry {
  # tc服務(wù)的注冊(cè)中心類,這里選擇nacos,也可以是eureka、zookeeper等
  type = "nacos"
  nacos {
    # seata tc 服務(wù)注冊(cè)到 nacos的服務(wù)名稱,可以自定義
    application = "seata-tc-server"
    serverAddr = "127.0.0.1:8848"
    group = "DEFAULT_GROUP"
    namespace = ""
    cluster = "HZ"
    username = "nacos"
    password = "nacos"
  }
}
config {
  # 讀取tc服務(wù)端的配置文件的方式,這里是從nacos配置中心讀取,這樣如果tc是集群,可以共享配置
  type = "nacos"
  # 配置nacos地址等信息
  nacos {
    serverAddr = "127.0.0.1:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = "nacos"
    password = "nacos"
    dataId = "seataServer.properties"
  }
}

進(jìn)入seata2/bin目錄,然后運(yùn)行命令:

seata-server.bat -p 8092

打開(kāi)nacos控制臺(tái),查看服務(wù)列表:

點(diǎn)進(jìn)詳情查看:

2.將事務(wù)組映射配置到nacos

接下來(lái),我們需要將tx-service-groupcluster的映射關(guān)系都配置到nacos配置中心。

新建一個(gè)配置:

配置的內(nèi)容如下:

# 事務(wù)組映射關(guān)系
service.vgroupMapping.seata-demo=SH
service.enableDegrade=false
service.disableGlobalTransaction=false
# 與TC服務(wù)的通信配置
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=false
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
# RM配置
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
# TM配置
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
# undo日志配置
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
client.log.exceptionRate=100

3.微服務(wù)讀取nacos配置

接下來(lái),需要修改每一個(gè)微服務(wù)的application.yml文件,讓微服務(wù)讀取nacos中的client.properties文件:

seata:
  config:
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      username: nacos
      password: nacos
      group: SEATA_GROUP
      data-id: client.properties

重啟微服務(wù),現(xiàn)在微服務(wù)到底是連接tcSH集群,還是tcHZ集群,都統(tǒng)一由nacosclient.properties來(lái)決定了。

到此這篇關(guān)于SpringCloud分布式事務(wù)Seata部署和集成過(guò)程的文章就介紹到這了,更多相關(guān)SpringCloud Seata部署和集成內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 五分鐘手?jǐn)]一個(gè)Spring容器(萌芽版)

    五分鐘手?jǐn)]一個(gè)Spring容器(萌芽版)

    Spring的兩大內(nèi)核分別是IOC和AOP,其中最最核心的是IOC。這篇文章主要介紹了五分鐘,手?jǐn)]一個(gè)Spring容器的相關(guān)知識(shí),需要的朋友可以參考下
    2022-03-03
  • Java踩坑記錄之Arrays.AsList

    Java踩坑記錄之Arrays.AsList

    這篇文章主要給大家介紹了關(guān)于Java踩坑記錄之Arrays.AsList的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • 詳解spring boot 以jar的方式啟動(dòng)常用shell腳本

    詳解spring boot 以jar的方式啟動(dòng)常用shell腳本

    本篇文章主要介紹了詳解spring boot 以jar的方式啟動(dòng)常用shell腳本,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-09-09
  • Java編程實(shí)現(xiàn)生成給定范圍內(nèi)不重復(fù)隨機(jī)數(shù)的方法小結(jié)

    Java編程實(shí)現(xiàn)生成給定范圍內(nèi)不重復(fù)隨機(jī)數(shù)的方法小結(jié)

    這篇文章主要介紹了Java編程實(shí)現(xiàn)生成給定范圍內(nèi)不重復(fù)隨機(jī)數(shù)的方法,結(jié)合實(shí)例形式總結(jié)分析了java基于數(shù)學(xué)運(yùn)算與判斷實(shí)現(xiàn)不重復(fù)隨機(jī)數(shù)的生成功能,需要的朋友可以參考下
    2017-07-07
  • java模擬TCP通信實(shí)現(xiàn)客戶端上傳文件到服務(wù)器端

    java模擬TCP通信實(shí)現(xiàn)客戶端上傳文件到服務(wù)器端

    這篇文章主要為大家詳細(xì)介紹了java模擬TCP通信實(shí)現(xiàn)客戶端上傳文件到服務(wù)器端,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • IDEA內(nèi)存調(diào)試插件(好用)

    IDEA內(nèi)存調(diào)試插件(好用)

    本文給大家分享IDEA中一個(gè)很有用的內(nèi)存調(diào)試插件,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下
    2018-02-02
  • Struts2 ActionContext 中的數(shù)據(jù)詳解

    Struts2 ActionContext 中的數(shù)據(jù)詳解

    這篇文章主要介紹了Struts2 ActionContext 中的數(shù)據(jù)詳解,需要的朋友可以參考下
    2016-07-07
  • Spring?Boot的無(wú)縫銜接實(shí)踐案例

    Spring?Boot的無(wú)縫銜接實(shí)踐案例

    在快速迭代的軟件開(kāi)發(fā)環(huán)境中,無(wú)縫銜接是提升開(kāi)發(fā)效率、降低維護(hù)成本、增強(qiáng)系統(tǒng)穩(wěn)定性的關(guān)鍵,本文將深入解析Spring?Boot無(wú)縫銜接的幾大優(yōu)勢(shì),并通過(guò)實(shí)際案例和深入分析,展示這些優(yōu)勢(shì)如何在項(xiàng)目中發(fā)揮作用
    2024-08-08
  • 閱讀EnumSet抽象類源碼

    閱讀EnumSet抽象類源碼

    這篇文章主要介紹了閱讀EnumSet抽象類源碼,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-12-12
  • IDEA整合SSM框架實(shí)現(xiàn)網(wǎng)頁(yè)上顯示數(shù)據(jù)

    IDEA整合SSM框架實(shí)現(xiàn)網(wǎng)頁(yè)上顯示數(shù)據(jù)

    最近做了個(gè)小項(xiàng)目,該項(xiàng)目包在intellij idea中實(shí)現(xiàn)了ssm框架的整合以及實(shí)現(xiàn)訪問(wèn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05

最新評(píng)論