https://hub.docker.com/r/zhaoyunxing/seata
https://github.com/seata/seata-docker
https://github.com/seata/seata
https://hub.docker.com/r/seataio/seata-server
https://hub.docker.com/r/nacos/nacos-server
https://github.com/seata/seata-samples/tree/docker/springboot-dubbo-fescar
https://nacos.io/zh-cn/docs/quick-start.html
https://github.com/alibaba/nacos
docker run -d -p 8091:8091 --name seata -e SEATA_IP=104.149.162.230 -e SEATA_PORT=8091 --restart=always seataio/seata-server:latest
应用: database -> 添加服务: seata
zhaoyunxing/seata:latest
卷:
/etc/localtime:/etc/localtime:ro
/data/file:/data/file
端口:8091:8091
Dockerfile:
# https://hub.docker.com/_/openjdk
FROM centos:7.5.1804
# set label
LABEL maintainer="seata <niao.shuai123@163.com>"
# set environment
ENV SEATA_USER="seata" \
JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk" \
JAVA="/usr/lib/jvm/java-1.8.0-openjdk/bin/java" \
TIME_ZONE="Asia/Shanghai"
ARG SEATA_VERSION=0.5.1
WORKDIR /$BASE_DIR
RUN set -x \
&& yum update -y \
&& yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel wget iputils nc vim libcurl \
&& wget https://github.com/seata/seata/releases/download/v${SEATA_VERSION}/seata-server-${SEATA_VERSION}.tar.gz -P /home \
&& mkdir /opt/seata \
&& tar -xzvf /home/seata-server-${SEATA_VERSION}.tar.gz -C /opt/seata \
&& rm -rf /home/seata-server-${SEATA_VERSION}.tar.gz \
&& ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo '$TIME_ZONE' > /etc/timezone \
&& yum clean all
# 设置额外参数
ENV EXTRA_JVM_ARGUMENTS="-XX:MaxDirectMemorySize=1024M"
ENTRYPOINT ["sh","/opt/seata/bin/seata-server.sh"]
EXPOSE 8091
nacos
nacos/nacos-server:latest
变量:
MODE=standalone
卷:
/data/file:/data/file
端口:8848(http):8848
fescar
registry.cn-hangzhou.aliyuncs.com/slievrly/fescar:0.4.0
卷:
/data/file:/data/file
# nacos 控制台 http://localhost:8848/nacos/ 默认密码: nacos - nacos
前往Fescar Github官方页面下载最新版本的 https://github.com/alibaba/fescar/releases
前往Nacos Github官方页面下载最新版本的 https://github.com/alibaba/nacos/releases
clone此项目到本地,使用maven构建导入IDEA编辑器中,配置项目使用的maven仓库和JDK版本(1.8)
将sql目录中的sql脚本导入到mysql数据库中,在此之前先创建数据库 db_gts_fescar,设置用户名密码为root root
模块说明:
- samples-account 用户账户微服务模块
- samples-dubbo-business-call 业务发起方模块
- samples-common 项目公共架构模块
- samples-order 订单微服务模块
- samples-storage 库存微服务模块
首先启动Nacos和Fescar,中间件具体使用说明详见上述Github官方页
分别启动samples-account、samples-order、samples-storage、samples-dubbo-business-call四个模块,确定微服务都注册到Nacos和Fescar
使用Postman工具请求Post接口地址:http://localhost:8104/business/dubbo/buy 模拟发起下单业务请求,成功后返回200
接下来测试全局回滚功能,打开samples-dubbo-business-call模块下的 BusinessServiceImpl类,打开被注释的代码
if (!flag) {
throw new RuntimeException("测试抛异常后,分布式事务回滚!");
}再次请求测试发生异常后全局事务被回滚
签名:这个人很懒,什么也没有留下!