JTA+SpringBoot多数据源事务一致性(二)

本文介绍了在SpringBoot环境下,利用JTA实现多数据源事务一致性。通过配置开发环境,如STS、SpringBoot、JDK等,以及设置多个数据库,确保数据一致性的实践步骤。通过JTA的配置和连接池Atomikos,实现了业务中多个数据源的事务强一致性。
摘要由CSDN通过智能技术生成

一、开发环境

  1. sts或IDEA
  2. springboot1.5+
  3. JDK1.8+
  4. maven3.0+
  5. mysql5.7
  6. oracle11g+

二、实践

  1.  虚拟3个数据库,如:

             

  1. 为每个数据库建立一张表,以测试数据是否保持一致。
  2. 首先在主数据源建立一张配置多数据源的表,并把数据库连接地址,用户名和密码配置到数据库,如下:

  1.    引入JTA 配置 transactions.properties,把该文件放入到resource目录下:
    # SAMPLE PROPERTIES FILE FOR THE TRANSACTION SERVICE
    # THIS FILE ILLUSTRATES THE DIFFERENT SETTINGS FOR THE TRANSACTION MANAGER
    # UNCOMMENT THE ASSIGNMENTS TO OVERRIDE DEFAULT VALUES;
    
    # Required: factory implementation class of the transaction core.
    # NOTE: there is no default for this, so it MUST be specified! 
    # 
    com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
    
            
    # Set base name of file where messages are output 
    # (also known as the 'console file').
    #
    # com.atomikos.icatch.console_file_name = tm.out
    
    # Size limit (in bytes) for the console file;
    # negative means unlimited.
    #
    # com.atomikos.icatch.console_file_limit=-1
    
    # For size-limited console files, this option
    # specifies a number of rotating files to 
    # maintain.
    #
    # com.atomikos.icatch.console_file_count=1
    
    # Set the number of log writes between checkpoints
    #
    # com.atomikos.icatch.checkpoint_interval=500
    
    # Set output directory where console file and other files are to be put
    # make sure this directory exists!
    #
    # com.atomikos.icatch.output_dir = ./
    
    # Set directory of log files; make sure this directory exists!
    #
    # com.atomikos.icatch.log_base_dir = ./
    
    # Set base name of log file
    # this name will be  used as the first part of 
    # the system-generated log file name
    #
    # com.atomikos.icatch.log_base_name = tmlog
    
    # Set the max number of active local transactions 
    # or -1 for unlimited.
    #
    # com.atomikos.icatch.max_actives = 50 (原因)
    com.atomikos.icatch.max_actives = 20000
    
    # Set 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值