springclound的事务管理-LCN

1.准备环境:springboot2.0以上+mysql,redis+feign

 

redis安装:

1.官网https://redis.io/

2.下载压缩包

3.解压后的文件拷贝到 /user/local/目录下

  • 切换到:cd /usr/local/redis-4.0.10/
  • 编译测试 sudo make test
  • 编译安装 sudo make install
  • 安装成功后,输入redis-server启动redis

 

ps axu|grep redis

 

Kill -9 pid

 

 

 

配置Tx-Manager

2 将“txlcn-tm”module导入到springcloud项目中

启动类加上注解:@EnableDistributedTransaction

 

@EnableFeignClients(basePackages="boss.net.service")

@EnableEurekaClient

@SpringBootApplication

@MapperScan("boss.net.mapper")

@EnableDistributedTransaction

publicclassSdwanExceptionhandler5001{

 

publicstaticvoidmain(String[]args){

SpringApplication.run(SdwanExceptionhandler5001.class,args);

}

 

}

 

3 创建数据库 tx-manager

 

4  修改配置,主要配置mysql,注册中心

spring.application.name=tx-Manager

server.port=7970

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

#spring.datasource.url=jdbc:mysql://10.21.19.86:3306/sdwan_co_db_v3?characterEncoding=utf-8

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/tx-Manager?characterEncoding=UTF-8

spring.datasource.username=root

spring.datasource.password=123

#spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

#spring.jpa.hibernate.ddl-auto=update

 

 

#指定注册中心地址

eureka.client.serviceUrl.defaultZone=http://localhost:6001/eureka/

eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}

eureka.instance.prefer-ip-address=true

 

mybatis.configuration.map-underscore-to-camel-case=true

mybatis.configuration.use-generated-keys=true

 

#TxManagerHostIp

tx-lcn.manager.host=127.0.0.1

#TxClient连接请求端口

tx-lcn.manager.port=8070

#心跳检测时间(ms)

tx-lcn.manager.heart-time=15000

#分布式事务执行总时间

tx-lcn.manager.dtx-time=30000

#参数延迟删除时间单位ms

tx-lcn.message.netty.attr-delay-time=10000

tx-lcn.manager.concurrent-level=128

#开启日志

tx-lcn.logger.enabled=true

logging.level.com.codingapi=debug

#redis主机

spring.redis.host=127.0.0.1

#redis端口

spring.redis.port=6379

#redis密码

spring.redis.password=

 

 

5 。启动这个服务(启动这个服务之前先启动redis)

 

http://127.0.0.1:7970/admin/index.html#/     密码:codingapi

 

 

6 配置Tx-client

在需要启用事务的模块的pom加上依赖:

<dependency>

<groupId>com.codingapi.txlcn</groupId>

<artifactId>txlcn-tc</artifactId>

<version>5.0.2.RELEASE</version>

</dependency>

 

<dependency>

<groupId>com.codingapi.txlcn</groupId>

<artifactId>txlcn-txmsg-netty</artifactId>

<version>5.0.2.RELEASE</version>

</dependency>

 

 

启动类上加上注解  @EnableDistributedTransaction

 

@EnableFeignClients(basePackages="boss.net.service")

@EnableEurekaClient

@SpringBootApplication

@MapperScan("boss.net.mapper")

@EnableDistributedTransaction

publicclassSdwanExceptionhandler5001{

 

publicstaticvoidmain(String[]args){

SpringApplication.run(SdwanExceptionhandler5001.class,args);

}

 

}

 

 

在需要事务的方法上加上注解@LcnTransaction

 

 txlcn-tm的地址 https://download.csdn.net/my

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值