微服务-分布式事务-TX-LCN的Eureka版本实例

1 版本信息

spring-boot-starter-parent : 2.1.4.RELEASE
spring-cloud-dependencies:Greenwich.SR1
txlcn:5.0.2.RELEAS

2 环境

2.1 host设置

############## eureka 

127.0.0.1    my-peer1 

127.0.0.1    my-peer2

############## txlcn 

127.0.0.1 tmlcnserver.com

############## reids

192.168.65.11 springboot1


2.2 nginx设置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    
    ######## tm-lcn
    upstream  tmlcn{
        server 127.0.0.1:10021;
        server 127.0.0.1:10022;
    }
    server {
        listen       80;
        server_name  tmlcnserver.com;
        location / {
           proxy_pass http://tmlcn;
            ###nginx与上游服务器(真实访问的服务器)超时时间 后端服务器连接的超时时间_发起握手等候响应超时时间
            proxy_connect_timeout 1s;
            ###nginx发送给上游服务器(真实访问的服务器)超时时间
            proxy_send_timeout 1s;
            ### nginx接受上游服务器(真实访问的服务器)超时时间
            proxy_read_timeout 1s;
            index  index.html index.htm;
        }      
    }
}


2.3 redis默认配置即可

3 需求

    下单,订单增加1个,对应的物品的量减少1。也就是下单的业务中,调用订单服务生成1个订单,调用库存服务将该物品的量减少1,同时保证这两个数据库操作具有事务性。

    使用nginx配置事务中心高可用。

4 项目结构

5 数据库样例

5.1 tx-lcn

    在官网可以查到对应的数据表。

5.2 order订单表

CREATE TABLE `order` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `commodity_id` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

5.3 stock库存表

CREATE TABLE `stock` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `commodity_id` bigint(20) DEFAULT NULL,
  `stock_num` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

6 具体代码

https://download.csdn.net/download/u013256012/11313360

7 最后说明

    如果刚好你需要一个这样的实例,这里刚好可以提供。配置文件中的各个配置,可以在官网上进行查询。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TCC-Transaction是一个开源的TCC补偿性分布式事务框架。TCC是Try、Confirm、Cancel的缩写,表示事务的尝试、确认和取消阶段。TCC能够对分布式事务的各个资源进行分别锁定、提交和释放。它的优点是能够实现严格一致性并且具有较短的执行时间和高实时性要求。同时,TCC也具有一定的缺点,例如对应用的侵入性较强,需要实现每个分支的try、confirm和cancel操作,实现难度较大。 关于Spring Cloud分布式事务和TCC,可以使用TCC-Transaction框架来实现。TCC-Transaction可以作为可靠性事件投递的替代品,并作为Spring Cloud Stream或Spring Cloud Bus的基础组件。此外,TCC还需要在事务管理器(协调器)节点上以高可用集群方式部署,并使用多数派算法来避免集群发生脑裂问题。 在实际应用,TCC适用于一些需要严格一致性、执行时间短和实时性要求高的场景,例如红包和收付款业务。 更多关于TCC-Transaction框架的详细信息可以在其GitHub地址(https://github.com/changmingxie/tcc-transaction)和项目指南地址(https://github.com/changmingxie/tcc-transaction/wiki/使用指南1.2.x)找到。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [SpringCloud(6) 分布式事务【概念、常见框架选择 - tx-lcn】](https://blog.csdn.net/qq_38225558/article/details/86103229)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [Spring Cloud综合实战 - 基于TCC补偿模式的分布式事务](https://blog.csdn.net/Solarison/article/details/68061157)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值