分布式事务seata在consul中的配置
首先是服务端:下载自信版本的seata-server,我下载的是0.9版本,下载后修改2个文件
文章图片
QQ图片20191203180107.png registry.conf:
registry {# file 、nacos 、eureka、redis、zk、consul、etcd3、sofatype = "consul"consul {cluster = "seata-server" consul中显示的服务名serverAddr = "10.241.95.107:8500,10.241.95.105:8500,10.241.95.106:8500"}}config {# file、nacos 、apollo、zk、consul、etcd3type = "file"file {name = "file.conf"}}
file.conf:
transport {# tcp udt unix-domain-sockettype = "TCP"#NIO NATIVEserver = "NIO"#enable heartbeatheartbeat = true#thread factory for nettythread-factory {boss-thread-prefix = "NettyBoss"worker-thread-prefix = "NettyServerNIOWorker"server-executor-thread-prefix = "NettyServerBizHandler"share-boss-worker = falseclient-selector-thread-prefix = "NettyClientSelector"client-selector-thread-size = 1client-worker-thread-prefix = "NettyClientWorkerThread"# netty boss thread size,will not be used for UDTboss-thread-size = 1#auto default pin or 8worker-thread-size = 8}shutdown {# when destroy server, wait secondswait = 3}serialization = "seata"compressor = "none"}service {#vgroup->rgroupvgroup_mapping.gzm= "default" 需要于客户端中的设定一致#only support single nodedefault.grouplist = "127.0.0.1:8091"#degrade current not supportenableDegrade = false#disabledisable = false#unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanentmax.commit.retry.timeout = "-1"max.rollback.retry.timeout = "-1"}client {async.commit.buffer.limit = 10000lock {retry.internal = 10retry.times = 30}report.retry.count = 5tm.commit.retry.count = 1tm.rollback.retry.count = 1}## transaction log storestore {## store mode: file、dbmode = "db"## database storedb {## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.datasource = "dbcp"## mysql/oracle/h2/oceanbase etc.db-type = "mysql"driver-class-name = "com.mysql.jdbc.Driver"url = "jdbc:mysql://xxxxx:3306/seata-server"user = "xxxxx"password = "xxxxx"min-conn = 1max-conn = 3global.table = "global_table"branch.table = "branch_table"lock-table = "lock_table"query-limit = 100}}lock {## the lock store mode: local、remotemode = "remote"local {## store locks in user's database}remote {## store locks in the seata's server}}recovery {#schedule committing retry period in millisecondscommitting-retry-period = 1000#schedule asyn committing retry period in millisecondsasyn-committing-retry-period = 1000#schedule rollbacking retry period in millisecondsrollbacking-retry-period = 1000#schedule timeout retry period in millisecondstimeout-retry-period = 1000}transaction {undo.data.validation = trueundo.log.serialization = "jackson"undo.log.save.days = 7#schedule delete expired undo_log in millisecondsundo.log.delete.period = 86400000undo.log.table = "undo_log"}## metrics settingsmetrics {enabled = falseregistry-type = "compact"# multi exporters use comma dividedexporter-list = "prometheus"exporter-prometheus-port = 9898}support {## springspring {# auto proxy the DataSource beandatasource.autoproxy = false}}
客户端:
配置文件
spring:application:name: test-servercloud:alibaba:seata:tx-service-group: gzm 需要与服务端一致consul:host: localhostport: 8500enabled: truediscovery:enabled: trueservice-name: test-serverprefer-ip-address: trueheartbeat:enabled: trueinstance-id: xxxx
pom文件
com.alibaba.cloud spring-cloud-alibaba-seata2.1.0.RELEASE seata-allio.seata io.seata seata-all${seata.version}
然后导入服务端的配置file.conf和registry.conf即可。
数据库修正:
把seata-server中自带的Sql执行下,同时需要在每个应用的数据库中同样加入undo_log。
以上就是seata在consul中的使用。
【分布式事务seata在consul中的配置】PS:seata客户端中任一应用重启都需要将关联的应用一并重启,不然会报i.s.c.r.netty.NettyClientChannelManager : no available server to connect.的错误。
推荐阅读
- 深入浅出谈一下有关分布式消息技术(Kafka)
- mysql中视图事务索引与权限管理
- KubeDL HostNetwork(加速分布式训练通信效率)
- spring事务管理_01:事务管理框架+声明式事务
- 2018-03-11|2018-03-11 存储过程
- 实操Redission|实操Redission 分布式服务
- 分布式|《Python3网络爬虫开发实战(第二版)》内容介绍
- SpringBoot解决Shiro导致依赖注入的bean事务失效问题
- 2021年行业社群孵化的分布式商业趋势
- 啥是负载均衡、高并发、分布式、集群()