阿里分布式事務(wù)-seata

使用步驟:

一浩习、安裝

下載seata-server:https://github.com/seata/seata/releases

我安裝的是0.6.1版本

解壓到/data/tool/seata-server/distribution

#運(yùn)行seata-server

sh /data/tool/seata-server/distribution/bin/seata-server.sh 8091 file /data/tool/seata-server/distribution/data

效果圖:


線程守護(hù)同目錄執(zhí)行:touch startup.sh

#!/bin/bash

sh /data/tool/seata-server/distribution/bin/seata-server.sh 8091 file /data/tool/seata-server/distribution/data

vim /lib/systemd/system/seata-server.service

文件中填入

[Unit]

Description=seata-server

After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]

Type=simple

ExecStart=/opt/seata-server/startup.sh

Restart=always

PrivateTmp=true

[Install]

WantedBy=multi-user.target

賦予權(quán)限

chmod 777 /data/tool/seata-server/distribution/startup.sh

chmod 777 /lib/systemd/system/seata-server.service

啟用服務(wù)

systemctl enable seata-server.service

systemctl daemon-reload

運(yùn)行

systemctl start seata-server.service

查看狀態(tài)

systemctl status seata-server.service

查看進(jìn)程

ps -ef|grep seata-server

運(yùn)行成功后可在Nacos控制臺(tái)的 服務(wù)列表 看到 服務(wù)名serverAddr的條目

注意:

每一個(gè)業(yè)務(wù)庫(kù)里都需要新增以下數(shù)據(jù)表

CREATE TABLE `undo_log` (

`id` bigint(20) NOT NULL AUTO_INCREMENT,

`branch_id` bigint(20) NOT NULL,

`xid` varchar(100) NOT NULL,

`rollback_info` longblob NOT NULL,

`log_status` int(11) NOT NULL,

`log_created` datetime NOT NULL,

`log_modified` datetime NOT NULL,

`ext` varchar(100) DEFAULT NULL,

PRIMARY KEY (`id`),

UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)

) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

二丹拯、spring cloud接入

1绎谦、配置文件 bootstrap.yml

spring:

? cloud: #分布式事務(wù)

? ? alibaba:

? ? ? seata:

? ? ? ? tx-service-group: default

2兼都、pom引用

<!--服務(wù)發(fā)現(xiàn)-->

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>

</dependency>

<!--feign-->

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-openfeign</artifactId>

</dependency>

<!--db-->

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-alibaba-seata</artifactId>

</dependency>

<dependency>

<groupId>io.seata</groupId>

<artifactId>seata-spring</artifactId>

</dependency>

<!--db end-->

3泄伪、把兩個(gè)文件copy到resources失都。

registry.conf

registry {

? # file 、nacos 庙曙、eureka空镜、redis、zk

? type = "file"

? nacos {

? ? serverAddr = "localhost"

? ? namespace = "public"

? ? cluster = "default"

? }

? eureka {

? ? serviceUrl = "http://localhost:1001/eureka"

? ? application = "default"

? ? weight = "1"

? }

? redis {

? ? serverAddr = "localhost:6381"

? ? db = "0"

? }

? zk {

? ? cluster = "default"

? ? serverAddr = "127.0.0.1:2181"

? ? session.timeout = 6000

? ? connect.timeout = 2000

? }

? file {

? ? name = "file.conf"

? }

}

config {

? # file捌朴、nacos 吴攒、apollo、zk

? type = "file"

? nacos {

? ? serverAddr = "localhost"

? ? namespace = "public"

? ? cluster = "default"

? }

? apollo {

? ? app.id = "fescar-server"

? ? apollo.meta = "http://192.168.1.204:8801"

? }

? zk {

? ? serverAddr = "127.0.0.1:2181"

? ? session.timeout = 6000

? ? connect.timeout = 2000

? }

? file {

? ? name = "file.conf"

? }

}

注意:

分組名稱:vgroup_mapping.default = "default"

nacos地址:default.grouplist = "seata-server:8091"

file.conf

transport {

? # tcp udt unix-domain-socket

? type = "TCP"

? #NIO NATIVE

? server = "NIO"

? #enable heartbeat

? heartbeat = true

? #thread factory for netty

? thread-factory {

? ? boss-thread-prefix = "NettyBoss"

? ? worker-thread-prefix = "NettyServerNIOWorker"

? ? server-executor-thread-prefix = "NettyServerBizHandler"

? ? share-boss-worker = false

? ? client-selector-thread-prefix = "NettyClientSelector"

? ? client-selector-thread-size = 1

? ? client-worker-thread-prefix = "NettyClientWorkerThread"

? ? # netty boss thread size,will not be used for UDT

? ? boss-thread-size = 1

? ? #auto default pin or 8

? ? worker-thread-size = 8

? }

}

service {

? #vgroup->rgroup

? vgroup_mapping.default = "default"

? #only support single node

? default.grouplist = "seata-server:8091"

? #degrade current not support

? enableDegrade = false

? #disable

? disable = false

? disableGlobalTransaction = false

}

client {

? async.commit.buffer.limit = 10000

? lock {

? ? retry.internal = 10

? ? retry.times = 30

? }

}

4砂蔽、代碼

主方法添加:

@GlobalTransactional

子方法添加:

@Transactional(rollbackFor = Exception.class)


來源:

https://blog.csdn.net/zhangchangbin123/article/details/89310131

安裝教程:

https://www.cnblogs.com/wintersoft/p/10548177.html

原理:

https://blog.csdn.net/hosaos/article/details/89136666#_251

#demo-seata-springcloud

https://github.com/SLY1311220942/demo-seata-springcloud

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末洼怔,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子察皇,更是在濱河造成了極大的恐慌,老刑警劉巖泽台,帶你破解...
    沈念sama閱讀 221,888評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件什荣,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡怀酷,警方通過查閱死者的電腦和手機(jī)稻爬,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,677評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蜕依,“玉大人桅锄,你說我怎么就攤上這事⊙撸” “怎么了友瘤?”我有些...
    開封第一講書人閱讀 168,386評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)檐束。 經(jīng)常有香客問我辫秧,道長(zhǎng),這世上最難降的妖魔是什么被丧? 我笑而不...
    開封第一講書人閱讀 59,726評(píng)論 1 297
  • 正文 為了忘掉前任盟戏,我火速辦了婚禮绪妹,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘柿究。我一直安慰自己邮旷,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,729評(píng)論 6 397
  • 文/花漫 我一把揭開白布蝇摸。 她就那樣靜靜地躺著婶肩,像睡著了一般。 火紅的嫁衣襯著肌膚如雪探入。 梳的紋絲不亂的頭發(fā)上狡孔,一...
    開封第一講書人閱讀 52,337評(píng)論 1 310
  • 那天,我揣著相機(jī)與錄音蜂嗽,去河邊找鬼苗膝。 笑死,一個(gè)胖子當(dāng)著我的面吹牛植旧,可吹牛的內(nèi)容都是我干的辱揭。 我是一名探鬼主播,決...
    沈念sama閱讀 40,902評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼病附,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼问窃!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起完沪,我...
    開封第一講書人閱讀 39,807評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤域庇,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后覆积,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體听皿,經(jīng)...
    沈念sama閱讀 46,349評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,439評(píng)論 3 340
  • 正文 我和宋清朗相戀三年宽档,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了尉姨。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,567評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡吗冤,死狀恐怖又厉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情椎瘟,我是刑警寧澤覆致,帶...
    沈念sama閱讀 36,242評(píng)論 5 350
  • 正文 年R本政府宣布,位于F島的核電站肺蔚,受9級(jí)特大地震影響篷朵,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,933評(píng)論 3 334
  • 文/蒙蒙 一声旺、第九天 我趴在偏房一處隱蔽的房頂上張望笔链。 院中可真熱鬧,春花似錦腮猖、人聲如沸鉴扫。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,420評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽坪创。三九已至,卻和暖如春姐赡,著一層夾襖步出監(jiān)牢的瞬間莱预,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,531評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工项滑, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留依沮,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,995評(píng)論 3 377
  • 正文 我出身青樓枪狂,卻偏偏與公主長(zhǎng)得像危喉,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子州疾,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,585評(píng)論 2 359