diff --git a/at-sample/pom.xml b/at-sample/pom.xml new file mode 100644 index 000000000..143cb7f16 --- /dev/null +++ b/at-sample/pom.xml @@ -0,0 +1,27 @@ + + + + 4.0.0 + pom + + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + + + io.seata + at-sample + 1.1.0 + + + seata-springcloud-nacos-sample + seata-springcloud-eureka-sample + seata-springcloud-consul-sample + + + + 1.8 + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/account/pom.xml b/at-sample/seata-springcloud-consul-sample/account/pom.xml new file mode 100644 index 000000000..ea11f0903 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/account/pom.xml @@ -0,0 +1,92 @@ + + + + org.seata + seata-springcloud-consul-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.account + account-service + 1.0.0-SNAPSHOT + account-service + 账户服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-consul-config + + + org.springframework.cloud + spring-cloud-starter-consul-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/AccountApplication.java b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/AccountApplication.java new file mode 100644 index 000000000..ecd8b0244 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/AccountApplication.java @@ -0,0 +1,20 @@ +package com.seata.account; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.account.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class AccountApplication { + + + public static void main(String[] args) { + SpringApplication.run(AccountApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/controller/AccountController.java b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/controller/AccountController.java new file mode 100644 index 000000000..53d659e4b --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/controller/AccountController.java @@ -0,0 +1,21 @@ +package com.seata.account.controller; + + +import com.seata.account.service.AccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AccountController { + @Autowired + private AccountService accountService; + + @GetMapping("account/debit") + public void debit(String userId, int money){ + + accountService.debit(userId,money); + }; + +} diff --git a/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java new file mode 100644 index 000000000..1e57aa495 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java @@ -0,0 +1,21 @@ +package com.seata.account.mapper; + + +import com.seata.account.model.Account; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface AccountMapper extends Mapper { + + /** + * 从用户账户中借出 + */ + @Update("update account_tbl set money = money - #{money} where user_id = #{userId}") + void debit(String userId, int money); + +} diff --git a/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/model/Account.java b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/model/Account.java new file mode 100644 index 000000000..f517691dd --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/model/Account.java @@ -0,0 +1,25 @@ +package com.seata.account.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "account_tbl") +@Data +@Accessors(chain = true) +public class Account { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/service/AccountService.java b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/service/AccountService.java new file mode 100644 index 000000000..124c7a3e2 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/service/AccountService.java @@ -0,0 +1,8 @@ +package com.seata.account.service; + + + +public interface AccountService { + + void debit(String userId, int money); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java new file mode 100644 index 000000000..e93d4205f --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java @@ -0,0 +1,24 @@ +package com.seata.account.service.impl; + + +import com.seata.account.mapper.AccountMapper; +import com.seata.account.service.AccountService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + + +@Slf4j +@Service +public class AccountServiceImpl implements AccountService { + + @Autowired + private AccountMapper accountMapper; + + + @Override + public void debit(String userId, int money) { + accountMapper.debit(userId,money); + } +} diff --git a/at-sample/seata-springcloud-consul-sample/account/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-consul-sample/account/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..f5076b761 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/account/src/main/resources/bootstrap.yml @@ -0,0 +1,34 @@ +server: + port: 6760 +spring: + application: + name: account-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + + cloud: + consul: + discovery: + service-name: ${spring.application.name} + heartbeat: + enabled: true + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + account-service-tx-group: "default" + grouplist: + default: 127.0.0.1:9080 + registry: + consul: + server-addr: 127.0.0.1:8500 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/business/pom.xml b/at-sample/seata-springcloud-consul-sample/business/pom.xml new file mode 100644 index 000000000..a556803da --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/business/pom.xml @@ -0,0 +1,77 @@ + + + + org.seata + seata-springcloud-consul-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.business + business-service + 1.0.0-SNAPSHOT + business-service + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-consul-config + + + org.springframework.cloud + spring-cloud-starter-consul-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/BusinessApplication.java b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/BusinessApplication.java similarity index 75% rename from springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/BusinessApplication.java rename to at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/BusinessApplication.java index fe0c1fea1..856db6ab2 100644 --- a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/BusinessApplication.java +++ b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/BusinessApplication.java @@ -1,13 +1,17 @@ -package io.seata.sample; +package com.seata.business; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; + @SpringBootApplication +@EnableDiscoveryClient @EnableFeignClients public class BusinessApplication { + public static void main(String[] args) { SpringApplication.run(BusinessApplication.class, args); } diff --git a/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/AccountClient.java b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/AccountClient.java new file mode 100644 index 000000000..06fd5c85f --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/AccountClient.java @@ -0,0 +1,16 @@ +package com.seata.business.client; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "account-service") +@Component +public interface AccountClient { + + @GetMapping("account/debit") + public void debit(@RequestParam("userId") String userId, @RequestParam("money")int money); + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/InventoryClient.java b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/InventoryClient.java new file mode 100644 index 000000000..d301633c2 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/InventoryClient.java @@ -0,0 +1,19 @@ +package com.seata.business.client; + + + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "inventory-service") +@Component +public interface InventoryClient { + + @GetMapping("inventory/deduct") + public void deduct(@RequestParam("commodityCode") String commodityCode , @RequestParam("count") int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/OrderClient.java b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/OrderClient.java new file mode 100644 index 000000000..259b23750 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/client/OrderClient.java @@ -0,0 +1,18 @@ +package com.seata.business.client; + +import com.seata.business.model.Order; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + + + +@FeignClient(name = "order-service") +@Component +public interface OrderClient { + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order); + +} diff --git a/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/controller/BusinessController.java b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/controller/BusinessController.java new file mode 100644 index 000000000..ba2695825 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/controller/BusinessController.java @@ -0,0 +1,37 @@ +package com.seata.business.controller; + +import com.seata.business.client.AccountClient; +import com.seata.business.client.InventoryClient; +import com.seata.business.client.OrderClient; +import com.seata.business.model.Order; +import io.seata.spring.annotation.GlobalTransactional; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class BusinessController { + @Autowired + private OrderClient orderClient; + @Autowired + private InventoryClient inventoryClient; + @Autowired + private AccountClient accountClient; + + @GetMapping("business/buy") + @GlobalTransactional + public String buy( String userId, String commodityCode, int count){ + int money = count * 1; + accountClient.debit(userId,money); + Order order = new Order(); + order.setUserId(userId); + order.setCommodityCode(commodityCode); + order.setCount(count); + order.setMoney(money); + orderClient.create(order); + inventoryClient.deduct(commodityCode,count); + return "success"; + } + +} diff --git a/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/model/Order.java b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/model/Order.java new file mode 100644 index 000000000..6cba50734 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/business/src/main/java/com/seata/business/model/Order.java @@ -0,0 +1,19 @@ +package com.seata.business.model; + +import lombok.Data; + +@Data +public class Order { + + + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/business/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-consul-sample/business/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..e1a84ed89 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/business/src/main/resources/bootstrap.yml @@ -0,0 +1,27 @@ +server: + port: 6750 +spring: + application: + name: business-service + + cloud: + consul: + discovery: + service-name: ${spring.application.name} + heartbeat: + enabled: true +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + business-service-tx-group: "default" + grouplist: + default: 127.0.0.1:9080 + + + registry: + consul: + server-addr: 127.0.0.1:8500 \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/inventory/pom.xml b/at-sample/seata-springcloud-consul-sample/inventory/pom.xml new file mode 100644 index 000000000..6857ea1ae --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/inventory/pom.xml @@ -0,0 +1,91 @@ + + + + org.seata + seata-springcloud-consul-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.inventory + inventory-service + 1.0.0-SNAPSHOT + inventory-service + 仓储服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-consul-config + + + org.springframework.cloud + spring-cloud-starter-consul-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java new file mode 100644 index 000000000..adfad30c6 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java @@ -0,0 +1,21 @@ +package com.seata.inventory; + +// +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.inventory.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class InventoryApplication { + public static void main(String[] args) { + SpringApplication.run(InventoryApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java new file mode 100644 index 000000000..d06a4daf6 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java @@ -0,0 +1,18 @@ +package com.seata.inventory.controller; + +import com.seata.inventory.service.InventoryService; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class InventoryController { + @Autowired + private InventoryService inventoryService; + + @GetMapping("inventory/deduct") + public void deduct(@Param("commodityCode") String commodityCode , @Param("count") int count) { + inventoryService.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java new file mode 100644 index 000000000..4a625496c --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java @@ -0,0 +1,15 @@ +package com.seata.inventory.mapper; + +import com.seata.inventory.model.Inventory; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface InventoryMapper extends Mapper { + + @Update("update inventory_tbl set count = count - #{count} where commodity_code = #{commodityCode}") + void deduct(@Param("commodityCode") String commodityCode , @Param("count") int count); +} diff --git a/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java new file mode 100644 index 000000000..51635196e --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java @@ -0,0 +1,25 @@ +package com.seata.inventory.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "inventory_tbl") +@Data +@Accessors(chain = true) +public class Inventory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String commodityCode; + + private Integer count; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java new file mode 100644 index 000000000..963b59ee8 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java @@ -0,0 +1,6 @@ +package com.seata.inventory.service; + +public interface InventoryService { + + void deduct(String commodityCode , int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java new file mode 100644 index 000000000..65ff61364 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java @@ -0,0 +1,23 @@ +package com.seata.inventory.service.impl; + +import com.seata.inventory.mapper.InventoryMapper; +import com.seata.inventory.service.InventoryService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class InventoryServiceImpl implements InventoryService { + + @Autowired + private InventoryMapper inventoryMapper; + + + @Override + public void deduct(String commodityCode, int count) { + inventoryMapper.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-consul-sample/inventory/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-consul-sample/inventory/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..c81d18160 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/inventory/src/main/resources/bootstrap.yml @@ -0,0 +1,35 @@ +server: + port: 6780 +spring: + application: + name: inventory-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + cloud: + consul: + discovery: + service-name: ${spring.application.name} + heartbeat: + enabled: true + + + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + inventory-service-tx-group: "default" + grouplist: + default: 127.0.0.1:9080 + registry: + consul: + server-addr: 127.0.0.1:8500 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/order/pom.xml b/at-sample/seata-springcloud-consul-sample/order/pom.xml new file mode 100644 index 000000000..8fcd2c849 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/order/pom.xml @@ -0,0 +1,92 @@ + + + + org.seata + seata-springcloud-consul-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.order + order-service + 1.0.0-SNAPSHOT + order-service + 订单服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-consul-config + + + org.springframework.cloud + spring-cloud-starter-consul-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/OrderApplication.java b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/OrderApplication.java similarity index 64% rename from springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/OrderApplication.java rename to at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/OrderApplication.java index 5ac66179d..1cb0eb485 100644 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/OrderApplication.java +++ b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/OrderApplication.java @@ -1,15 +1,20 @@ -package io.seata; +package com.seata.order; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; @SpringBootApplication +@MapperScan("com.seata.order.mapper") +@EnableDiscoveryClient @EnableFeignClients -@MapperScan("io.seata.order.mapper") public class OrderApplication { + + public static void main(String[] args) { SpringApplication.run(OrderApplication.class, args); } + } diff --git a/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/controller/OrderController.java b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/controller/OrderController.java new file mode 100644 index 000000000..1b876ef47 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/controller/OrderController.java @@ -0,0 +1,23 @@ +package com.seata.order.controller; + + +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; + +@RestController +public class OrderController { + @Autowired + private OrderService orderService; + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order){ + + return orderService.create(order); + } +} diff --git a/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java new file mode 100644 index 000000000..fc3a21ee6 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java @@ -0,0 +1,12 @@ +package com.seata.order.mapper; + + +import com.seata.order.model.Order; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface OrderMapper extends Mapper { + +} diff --git a/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/model/Order.java b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/model/Order.java new file mode 100644 index 000000000..9200efc82 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/model/Order.java @@ -0,0 +1,29 @@ +package com.seata.order.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "order_tbl") +@Data +@Accessors(chain = true) +public class Order { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/service/OrderService.java b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/service/OrderService.java new file mode 100644 index 000000000..d85651465 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/service/OrderService.java @@ -0,0 +1,8 @@ +package com.seata.order.service; + +import com.seata.order.model.Order; + +public interface OrderService { + + boolean create(Order order); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java new file mode 100644 index 000000000..5d3e2632d --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java @@ -0,0 +1,27 @@ +package com.seata.order.service.impl; + + +import com.seata.order.mapper.OrderMapper; +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class OrderServiceImpl implements OrderService { + + @Autowired + private OrderMapper orderMapper; + + @Override + public boolean create(Order order) { + log.info("创建订单开始"); + int index = orderMapper.insert(order); + log.info("创建订单结束"); + return index > 0; + } +} diff --git a/at-sample/seata-springcloud-consul-sample/order/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-consul-sample/order/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..7af556f86 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/order/src/main/resources/bootstrap.yml @@ -0,0 +1,38 @@ +server: + port: 6770 +spring: + application: + name: order-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + cloud: + consul: + discovery: + service-name: ${spring.application.name} + heartbeat: + enabled: true + + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + order-service-tx-group: "default" + grouplist: + default: 127.0.0.1:9080 +# config: +# type: consul +# consul: +# server-addr: 127.0.0.1:8500 + registry: + consul: + server-addr: 127.0.0.1:8500 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/pom.xml b/at-sample/seata-springcloud-consul-sample/pom.xml new file mode 100644 index 000000000..f7325a8e4 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/pom.xml @@ -0,0 +1,66 @@ + + +pom + + inventory + order + account + business + + + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + + +4.0.0 + +org.seata +seata-springcloud-consul-sample +1.0-SNAPSHOT + + + 2.4.2.RELEASE + 1.8 + 2.1.5 + 4.1.5 + 1.3.0 + + + + + + + tk.mybatis + mapper-spring-boot-starter + ${mybatis.version} + + + tk.mybatis + mapper + ${tk-mapper.version} + + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR9 + pom + import + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.1.RELEASE + pom + import + + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/seata-server/pom.xml b/at-sample/seata-springcloud-consul-sample/seata-server/pom.xml new file mode 100644 index 000000000..cde3676ae --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/seata-server/pom.xml @@ -0,0 +1,89 @@ + + + + org.seata + seata-springcloud-consul-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.server + seata-server + 1.0.0-SNAPSHOT + seata-server + seata-server + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-consul-config + + + org.springframework.cloud + spring-cloud-starter-consul-discovery + + + + + + + + + + + + + + + + + + + + io.seata + seata-server + 1.5.2 + + + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/seata-server/src/main/java/com/sever/ServerApplication.java b/at-sample/seata-springcloud-consul-sample/seata-server/src/main/java/com/sever/ServerApplication.java new file mode 100644 index 000000000..9854f0b33 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/seata-server/src/main/java/com/sever/ServerApplication.java @@ -0,0 +1,14 @@ +package com.sever; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.io.IOException; + +@SpringBootApplication(scanBasePackages = {"io.seata"}) +public class ServerApplication { + public static void main(String[] args) throws IOException { + // run the spring-boot application + SpringApplication.run(com.sever.ServerApplication.class, args); + } +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-consul-sample/seata-server/src/main/resources/application.yml b/at-sample/seata-springcloud-consul-sample/seata-server/src/main/resources/application.yml new file mode 100644 index 000000000..53c1dc5a6 --- /dev/null +++ b/at-sample/seata-springcloud-consul-sample/seata-server/src/main/resources/application.yml @@ -0,0 +1,76 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos, consul, apollo, zk, etcd3 + type: file + consul: + server-addr: 127.0.0.1:8500 + acl-token: + key: seata.properties + + registry: + # support: nacos, eureka, redis, zk, consul, etcd3, sofa + type: consul + preferred-networks: 30.240.* + consul: + cluster: default + server-addr: 127.0.0.1:8500 + acl-token: + store: + # support: file 、 db 、 redis + mode: file + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druids + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar + user: workshop + password: Workshop123 + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login \ No newline at end of file diff --git a/springcloud-eureka-feign-mybatis-seata/README.md b/at-sample/seata-springcloud-eureka-sample/README.md similarity index 100% rename from springcloud-eureka-feign-mybatis-seata/README.md rename to at-sample/seata-springcloud-eureka-sample/README.md diff --git a/at-sample/seata-springcloud-eureka-sample/account/pom.xml b/at-sample/seata-springcloud-eureka-sample/account/pom.xml new file mode 100644 index 000000000..008007d5c --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/account/pom.xml @@ -0,0 +1,88 @@ + + + + org.seata + seata-springcloud-eureka-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.account + account-service + 1.0.0-SNAPSHOT + account-service + 账户服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/AccountApplication.java b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/AccountApplication.java new file mode 100644 index 000000000..ecd8b0244 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/AccountApplication.java @@ -0,0 +1,20 @@ +package com.seata.account; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.account.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class AccountApplication { + + + public static void main(String[] args) { + SpringApplication.run(AccountApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/controller/AccountController.java b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/controller/AccountController.java new file mode 100644 index 000000000..53d659e4b --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/controller/AccountController.java @@ -0,0 +1,21 @@ +package com.seata.account.controller; + + +import com.seata.account.service.AccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AccountController { + @Autowired + private AccountService accountService; + + @GetMapping("account/debit") + public void debit(String userId, int money){ + + accountService.debit(userId,money); + }; + +} diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/feign/OrderApi.java b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/feign/OrderApi.java similarity index 100% rename from springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/feign/OrderApi.java rename to at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/feign/OrderApi.java diff --git a/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java new file mode 100644 index 000000000..1e57aa495 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java @@ -0,0 +1,21 @@ +package com.seata.account.mapper; + + +import com.seata.account.model.Account; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface AccountMapper extends Mapper { + + /** + * 从用户账户中借出 + */ + @Update("update account_tbl set money = money - #{money} where user_id = #{userId}") + void debit(String userId, int money); + +} diff --git a/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/model/Account.java b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/model/Account.java new file mode 100644 index 000000000..f517691dd --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/model/Account.java @@ -0,0 +1,25 @@ +package com.seata.account.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "account_tbl") +@Data +@Accessors(chain = true) +public class Account { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/service/AccountService.java b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/service/AccountService.java new file mode 100644 index 000000000..124c7a3e2 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/service/AccountService.java @@ -0,0 +1,8 @@ +package com.seata.account.service; + + + +public interface AccountService { + + void debit(String userId, int money); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java new file mode 100644 index 000000000..e93d4205f --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java @@ -0,0 +1,24 @@ +package com.seata.account.service.impl; + + +import com.seata.account.mapper.AccountMapper; +import com.seata.account.service.AccountService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + + +@Slf4j +@Service +public class AccountServiceImpl implements AccountService { + + @Autowired + private AccountMapper accountMapper; + + + @Override + public void debit(String userId, int money) { + accountMapper.debit(userId,money); + } +} diff --git a/at-sample/seata-springcloud-eureka-sample/account/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-eureka-sample/account/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..1395de660 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/account/src/main/resources/bootstrap.yml @@ -0,0 +1,38 @@ +server: + port: 6760 +spring: + application: + name: account-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + +eureka: + instance: + instance-id: account-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + account-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/test/java/io/seata/sample/AccountServerApplicationTests.java b/at-sample/seata-springcloud-eureka-sample/account/src/test/java/io/seata/sample/AccountServerApplicationTests.java similarity index 100% rename from springcloud-eureka-feign-mybatis-seata/account-server/src/test/java/io/seata/sample/AccountServerApplicationTests.java rename to at-sample/seata-springcloud-eureka-sample/account/src/test/java/io/seata/sample/AccountServerApplicationTests.java diff --git a/at-sample/seata-springcloud-eureka-sample/business/pom.xml b/at-sample/seata-springcloud-eureka-sample/business/pom.xml new file mode 100644 index 000000000..f5e8c31cc --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/business/pom.xml @@ -0,0 +1,72 @@ + + + + org.seata + seata-springcloud-eureka-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.business + business-service + 1.0.0-SNAPSHOT + business-service + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/BusinessApplication.java b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/BusinessApplication.java new file mode 100644 index 000000000..856db6ab2 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/BusinessApplication.java @@ -0,0 +1,19 @@ +package com.seata.business; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class BusinessApplication { + + + public static void main(String[] args) { + SpringApplication.run(BusinessApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/AccountClient.java b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/AccountClient.java new file mode 100644 index 000000000..06fd5c85f --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/AccountClient.java @@ -0,0 +1,16 @@ +package com.seata.business.client; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "account-service") +@Component +public interface AccountClient { + + @GetMapping("account/debit") + public void debit(@RequestParam("userId") String userId, @RequestParam("money")int money); + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/InventoryClient.java b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/InventoryClient.java new file mode 100644 index 000000000..d301633c2 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/InventoryClient.java @@ -0,0 +1,19 @@ +package com.seata.business.client; + + + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "inventory-service") +@Component +public interface InventoryClient { + + @GetMapping("inventory/deduct") + public void deduct(@RequestParam("commodityCode") String commodityCode , @RequestParam("count") int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/OrderClient.java b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/OrderClient.java new file mode 100644 index 000000000..259b23750 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/client/OrderClient.java @@ -0,0 +1,18 @@ +package com.seata.business.client; + +import com.seata.business.model.Order; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + + + +@FeignClient(name = "order-service") +@Component +public interface OrderClient { + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order); + +} diff --git a/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/controller/BusinessController.java b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/controller/BusinessController.java new file mode 100644 index 000000000..ba2695825 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/controller/BusinessController.java @@ -0,0 +1,37 @@ +package com.seata.business.controller; + +import com.seata.business.client.AccountClient; +import com.seata.business.client.InventoryClient; +import com.seata.business.client.OrderClient; +import com.seata.business.model.Order; +import io.seata.spring.annotation.GlobalTransactional; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class BusinessController { + @Autowired + private OrderClient orderClient; + @Autowired + private InventoryClient inventoryClient; + @Autowired + private AccountClient accountClient; + + @GetMapping("business/buy") + @GlobalTransactional + public String buy( String userId, String commodityCode, int count){ + int money = count * 1; + accountClient.debit(userId,money); + Order order = new Order(); + order.setUserId(userId); + order.setCommodityCode(commodityCode); + order.setCount(count); + order.setMoney(money); + orderClient.create(order); + inventoryClient.deduct(commodityCode,count); + return "success"; + } + +} diff --git a/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/model/Order.java b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/model/Order.java new file mode 100644 index 000000000..6cba50734 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/business/src/main/java/com/seata/business/model/Order.java @@ -0,0 +1,19 @@ +package com.seata.business.model; + +import lombok.Data; + +@Data +public class Order { + + + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/business/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-eureka-sample/business/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..d94a952fd --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/business/src/main/resources/bootstrap.yml @@ -0,0 +1,29 @@ +server: + port: 6750 +spring: + application: + name: business-service +eureka: + instance: + instance-id: business-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + business-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + eight: 1 \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/inventory/pom.xml b/at-sample/seata-springcloud-eureka-sample/inventory/pom.xml new file mode 100644 index 000000000..e034c6042 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/inventory/pom.xml @@ -0,0 +1,87 @@ + + + + org.seata + seata-springcloud-eureka-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.inventory + inventory-service + 1.0.0-SNAPSHOT + inventory-service + 仓储服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java new file mode 100644 index 000000000..adfad30c6 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java @@ -0,0 +1,21 @@ +package com.seata.inventory; + +// +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.inventory.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class InventoryApplication { + public static void main(String[] args) { + SpringApplication.run(InventoryApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java new file mode 100644 index 000000000..d06a4daf6 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java @@ -0,0 +1,18 @@ +package com.seata.inventory.controller; + +import com.seata.inventory.service.InventoryService; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class InventoryController { + @Autowired + private InventoryService inventoryService; + + @GetMapping("inventory/deduct") + public void deduct(@Param("commodityCode") String commodityCode , @Param("count") int count) { + inventoryService.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java new file mode 100644 index 000000000..4a625496c --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java @@ -0,0 +1,15 @@ +package com.seata.inventory.mapper; + +import com.seata.inventory.model.Inventory; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface InventoryMapper extends Mapper { + + @Update("update inventory_tbl set count = count - #{count} where commodity_code = #{commodityCode}") + void deduct(@Param("commodityCode") String commodityCode , @Param("count") int count); +} diff --git a/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java new file mode 100644 index 000000000..51635196e --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java @@ -0,0 +1,25 @@ +package com.seata.inventory.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "inventory_tbl") +@Data +@Accessors(chain = true) +public class Inventory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String commodityCode; + + private Integer count; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java new file mode 100644 index 000000000..963b59ee8 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java @@ -0,0 +1,6 @@ +package com.seata.inventory.service; + +public interface InventoryService { + + void deduct(String commodityCode , int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java new file mode 100644 index 000000000..65ff61364 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java @@ -0,0 +1,23 @@ +package com.seata.inventory.service.impl; + +import com.seata.inventory.mapper.InventoryMapper; +import com.seata.inventory.service.InventoryService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class InventoryServiceImpl implements InventoryService { + + @Autowired + private InventoryMapper inventoryMapper; + + + @Override + public void deduct(String commodityCode, int count) { + inventoryMapper.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-eureka-sample/inventory/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..7e1f4737e --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/inventory/src/main/resources/bootstrap.yml @@ -0,0 +1,39 @@ +server: + port: 6780 +spring: + application: + name: inventory-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + +eureka: + instance: + instance-id: inventory-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + inventory-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/test/java/io/seata/sample/StockServerApplicationTests.java b/at-sample/seata-springcloud-eureka-sample/inventory/src/test/java/io/seata/sample/StockServerApplicationTests.java similarity index 100% rename from springcloud-eureka-feign-mybatis-seata/storage-server/src/test/java/io/seata/sample/StockServerApplicationTests.java rename to at-sample/seata-springcloud-eureka-sample/inventory/src/test/java/io/seata/sample/StockServerApplicationTests.java diff --git a/at-sample/seata-springcloud-eureka-sample/order/pom.xml b/at-sample/seata-springcloud-eureka-sample/order/pom.xml new file mode 100644 index 000000000..58ec8feb0 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/order/pom.xml @@ -0,0 +1,88 @@ + + + + org.seata + seata-springcloud-eureka-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.order + order-service + 1.0.0-SNAPSHOT + order-service + 订单服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/OrderApplication.java b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/OrderApplication.java new file mode 100644 index 000000000..1cb0eb485 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/OrderApplication.java @@ -0,0 +1,20 @@ +package com.seata.order; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.order.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class OrderApplication { + + + public static void main(String[] args) { + SpringApplication.run(OrderApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/controller/OrderController.java b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/controller/OrderController.java new file mode 100644 index 000000000..1b876ef47 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/controller/OrderController.java @@ -0,0 +1,23 @@ +package com.seata.order.controller; + + +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; + +@RestController +public class OrderController { + @Autowired + private OrderService orderService; + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order){ + + return orderService.create(order); + } +} diff --git a/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java new file mode 100644 index 000000000..fc3a21ee6 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java @@ -0,0 +1,12 @@ +package com.seata.order.mapper; + + +import com.seata.order.model.Order; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface OrderMapper extends Mapper { + +} diff --git a/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/model/Order.java b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/model/Order.java new file mode 100644 index 000000000..9200efc82 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/model/Order.java @@ -0,0 +1,29 @@ +package com.seata.order.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "order_tbl") +@Data +@Accessors(chain = true) +public class Order { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/service/OrderService.java b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/service/OrderService.java new file mode 100644 index 000000000..d85651465 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/service/OrderService.java @@ -0,0 +1,8 @@ +package com.seata.order.service; + +import com.seata.order.model.Order; + +public interface OrderService { + + boolean create(Order order); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java new file mode 100644 index 000000000..5d3e2632d --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java @@ -0,0 +1,27 @@ +package com.seata.order.service.impl; + + +import com.seata.order.mapper.OrderMapper; +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class OrderServiceImpl implements OrderService { + + @Autowired + private OrderMapper orderMapper; + + @Override + public boolean create(Order order) { + log.info("创建订单开始"); + int index = orderMapper.insert(order); + log.info("创建订单结束"); + return index > 0; + } +} diff --git a/at-sample/seata-springcloud-eureka-sample/order/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-eureka-sample/order/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..95353c6d6 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/order/src/main/resources/bootstrap.yml @@ -0,0 +1,38 @@ +server: + port: 6770 +spring: + application: + name: order-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + +eureka: + instance: + instance-id: order-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + order-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/test/java/io/seata/sample/OrderServerApplicationTests.java b/at-sample/seata-springcloud-eureka-sample/order/src/test/java/io/seata/sample/OrderServerApplicationTests.java similarity index 100% rename from springcloud-eureka-feign-mybatis-seata/order-server/src/test/java/io/seata/sample/OrderServerApplicationTests.java rename to at-sample/seata-springcloud-eureka-sample/order/src/test/java/io/seata/sample/OrderServerApplicationTests.java diff --git a/at-sample/seata-springcloud-eureka-sample/pom.xml b/at-sample/seata-springcloud-eureka-sample/pom.xml new file mode 100644 index 000000000..1eb15bdf7 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/pom.xml @@ -0,0 +1,66 @@ + + + pom + + inventory + order + account + business + + + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + + + 4.0.0 + + org.seata + seata-springcloud-eureka-sample + 1.0-SNAPSHOT + + + 2.4.2.RELEASE + 1.8 + 2.1.5 + 4.1.5 + 1.3.0 + + + + + + + tk.mybatis + mapper-spring-boot-starter + ${mybatis.version} + + + tk.mybatis + mapper + ${tk-mapper.version} + + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR9 + pom + import + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.1.RELEASE + pom + import + + + + + \ No newline at end of file diff --git a/springcloud-jpa-seata/account-service/pom.xml b/at-sample/seata-springcloud-eureka-sample/seata-server/pom.xml old mode 100755 new mode 100644 similarity index 50% rename from springcloud-jpa-seata/account-service/pom.xml rename to at-sample/seata-springcloud-eureka-sample/seata-server/pom.xml index ffdba8a09..79dd41b03 --- a/springcloud-jpa-seata/account-service/pom.xml +++ b/at-sample/seata-springcloud-eureka-sample/seata-server/pom.xml @@ -1,63 +1,70 @@ - - io.seata - springcloud-jpa-seata - 1.1.0 + org.seata + seata-springcloud-eureka-sample + 1.0-SNAPSHOT 4.0.0 + com.seata.server + seata-server + 1.0.0-SNAPSHOT + seata-server + seata-server - account-service - jar - - account-service - Demo project for Spring Boot + + 1.8 + org.springframework.boot spring-boot-starter-web + + + org.projectlombok + lombok + true + org.springframework.boot spring-boot-starter-test test + + - mysql - mysql-connector-java - runtime + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + - com.alibaba - druid-spring-boot-starter + io.seata + seata-server + 1.5.2 + + + - org.springframework.boot - spring-boot-starter-data-jpa + mysql + mysql-connector-java + + org.springframework.cloud spring-cloud-starter-openfeign - com.alibaba.cloud - spring-cloud-alibaba-seata - - - io.seata - seata-all + io.github.openfeign + feign-okhttp + 10.2.3 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - + \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/seata-server/src/main/java/com/sever/ServerApplication.java b/at-sample/seata-springcloud-eureka-sample/seata-server/src/main/java/com/sever/ServerApplication.java new file mode 100644 index 000000000..4d869d5da --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/seata-server/src/main/java/com/sever/ServerApplication.java @@ -0,0 +1,14 @@ +package com.sever; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.io.IOException; + +@SpringBootApplication(scanBasePackages = {"io.seata"}) +public class ServerApplication { + public static void main(String[] args) throws IOException { + // run the spring-boot application + SpringApplication.run(ServerApplication.class, args); + } +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-eureka-sample/seata-server/src/main/resources/application.yml b/at-sample/seata-springcloud-eureka-sample/seata-server/src/main/resources/application.yml new file mode 100644 index 000000000..807dfc560 --- /dev/null +++ b/at-sample/seata-springcloud-eureka-sample/seata-server/src/main/resources/application.yml @@ -0,0 +1,73 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos, consul, apollo, zk, etcd3 + type: file + + registry: + # support: nacos, eureka, redis, zk, consul, etcd3, sofa + type: eureka + preferred-networks: 30.240.* + eureka: + service-url: http://localhost:8761/eureka + application: default + weight: 1 + + store: + # support: file 、 db 、 redis + mode: db + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druids + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar + user: workshop + password: Workshop123 + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login \ No newline at end of file diff --git a/springcloud-jpa-seata/README.md b/at-sample/seata-springcloud-jpa-sample/README.md similarity index 100% rename from springcloud-jpa-seata/README.md rename to at-sample/seata-springcloud-jpa-sample/README.md diff --git a/at-sample/seata-springcloud-jpa-sample/account/pom.xml b/at-sample/seata-springcloud-jpa-sample/account/pom.xml new file mode 100644 index 000000000..de07af8b9 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/account/pom.xml @@ -0,0 +1,84 @@ + + + + org.seata + seata-springcloud-jpa-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.account + account-service + 1.0.0-SNAPSHOT + account-service + 账户服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/AccountApplication.java b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/AccountApplication.java similarity index 79% rename from springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/AccountApplication.java rename to at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/AccountApplication.java index 032dc0ffd..8723bcbdd 100644 --- a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/AccountApplication.java +++ b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/AccountApplication.java @@ -1,16 +1,21 @@ -package io.seata.sample; +package com.seata.account; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + @SpringBootApplication +@EnableDiscoveryClient @EnableFeignClients @EnableJpaRepositories public class AccountApplication { + public static void main(String[] args) { SpringApplication.run(AccountApplication.class, args); } + } diff --git a/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/controller/AccountController.java b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/controller/AccountController.java new file mode 100644 index 000000000..53d659e4b --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/controller/AccountController.java @@ -0,0 +1,21 @@ +package com.seata.account.controller; + + +import com.seata.account.service.AccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AccountController { + @Autowired + private AccountService accountService; + + @GetMapping("account/debit") + public void debit(String userId, int money){ + + accountService.debit(userId,money); + }; + +} diff --git a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/repository/AccountDAO.java b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/dao/AccountDAO.java similarity index 54% rename from springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/repository/AccountDAO.java rename to at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/dao/AccountDAO.java index 5a4a9a40a..b278122df 100644 --- a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/repository/AccountDAO.java +++ b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/dao/AccountDAO.java @@ -1,14 +1,10 @@ -package io.seata.sample.repository; +package com.seata.account.dao; -import io.seata.sample.entity.Account; + +import com.seata.account.model.Account; import org.springframework.data.jpa.repository.JpaRepository; -/** - * Description: - * - * @author fangliangsheng - * @date 2019/3/28 - */ + public interface AccountDAO extends JpaRepository { Account findByUserId(String userId); diff --git a/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/model/Account.java b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/model/Account.java new file mode 100644 index 000000000..e0fbc1ce4 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/model/Account.java @@ -0,0 +1,24 @@ +package com.seata.account.model; + +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; + +@Entity +@Table(name = "account_tbl") +@Data +@DynamicUpdate +@DynamicInsert +public class Account { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/service/AccountService.java b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/service/AccountService.java new file mode 100644 index 000000000..124c7a3e2 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/service/AccountService.java @@ -0,0 +1,8 @@ +package com.seata.account.service; + + + +public interface AccountService { + + void debit(String userId, int money); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java new file mode 100644 index 000000000..7bcc0fdaf --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java @@ -0,0 +1,26 @@ +package com.seata.account.service.impl; + + + +import com.seata.account.dao.AccountDAO; +import com.seata.account.model.Account; +import com.seata.account.service.AccountService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + + +@Slf4j +@Service +public class AccountServiceImpl implements AccountService { + + @Autowired + private AccountDAO accountDAO; + + public void debit(String userId, int money) { + Account account = accountDAO.findByUserId(userId); + account.setMoney(account.getMoney() - money); + accountDAO.save(account); + } +} diff --git a/at-sample/seata-springcloud-jpa-sample/account/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-jpa-sample/account/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..1395de660 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/account/src/main/resources/bootstrap.yml @@ -0,0 +1,38 @@ +server: + port: 6760 +spring: + application: + name: account-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + +eureka: + instance: + instance-id: account-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + account-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/business/pom.xml b/at-sample/seata-springcloud-jpa-sample/business/pom.xml new file mode 100644 index 000000000..13783a5c6 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/business/pom.xml @@ -0,0 +1,72 @@ + + + + org.seata + seata-springcloud-jpa-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.business + business-service + 1.0.0-SNAPSHOT + business-service + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/BusinessApplication.java b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/BusinessApplication.java new file mode 100644 index 000000000..856db6ab2 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/BusinessApplication.java @@ -0,0 +1,19 @@ +package com.seata.business; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class BusinessApplication { + + + public static void main(String[] args) { + SpringApplication.run(BusinessApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/client/AccountClient.java b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/client/AccountClient.java new file mode 100644 index 000000000..d301633c2 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/client/AccountClient.java @@ -0,0 +1,19 @@ +package com.seata.business.client; + + + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "inventory-service") +@Component +public interface InventoryClient { + + @GetMapping("inventory/deduct") + public void deduct(@RequestParam("commodityCode") String commodityCode , @RequestParam("count") int count); +} \ No newline at end of file diff --git a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/feign/StockFeignClient.java b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/client/InventoryClient.java similarity index 100% rename from springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/feign/StockFeignClient.java rename to at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/client/InventoryClient.java diff --git a/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/client/OrderClient.java b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/client/OrderClient.java new file mode 100644 index 000000000..ba2695825 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/client/OrderClient.java @@ -0,0 +1,37 @@ +package com.seata.business.controller; + +import com.seata.business.client.AccountClient; +import com.seata.business.client.InventoryClient; +import com.seata.business.client.OrderClient; +import com.seata.business.model.Order; +import io.seata.spring.annotation.GlobalTransactional; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class BusinessController { + @Autowired + private OrderClient orderClient; + @Autowired + private InventoryClient inventoryClient; + @Autowired + private AccountClient accountClient; + + @GetMapping("business/buy") + @GlobalTransactional + public String buy( String userId, String commodityCode, int count){ + int money = count * 1; + accountClient.debit(userId,money); + Order order = new Order(); + order.setUserId(userId); + order.setCommodityCode(commodityCode); + order.setCount(count); + order.setMoney(money); + orderClient.create(order); + inventoryClient.deduct(commodityCode,count); + return "success"; + } + +} diff --git a/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/controller/BusinessController.java b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/controller/BusinessController.java new file mode 100644 index 000000000..ba2695825 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/controller/BusinessController.java @@ -0,0 +1,37 @@ +package com.seata.business.controller; + +import com.seata.business.client.AccountClient; +import com.seata.business.client.InventoryClient; +import com.seata.business.client.OrderClient; +import com.seata.business.model.Order; +import io.seata.spring.annotation.GlobalTransactional; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class BusinessController { + @Autowired + private OrderClient orderClient; + @Autowired + private InventoryClient inventoryClient; + @Autowired + private AccountClient accountClient; + + @GetMapping("business/buy") + @GlobalTransactional + public String buy( String userId, String commodityCode, int count){ + int money = count * 1; + accountClient.debit(userId,money); + Order order = new Order(); + order.setUserId(userId); + order.setCommodityCode(commodityCode); + order.setCount(count); + order.setMoney(money); + orderClient.create(order); + inventoryClient.deduct(commodityCode,count); + return "success"; + } + +} diff --git a/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/model/Order.java b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/model/Order.java new file mode 100644 index 000000000..6cba50734 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/business/src/main/java/com/seata/business/model/Order.java @@ -0,0 +1,19 @@ +package com.seata.business.model; + +import lombok.Data; + +@Data +public class Order { + + + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/business/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-jpa-sample/business/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..d94a952fd --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/business/src/main/resources/bootstrap.yml @@ -0,0 +1,29 @@ +server: + port: 6750 +spring: + application: + name: business-service +eureka: + instance: + instance-id: business-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + business-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + eight: 1 \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/inventory/pom.xml b/at-sample/seata-springcloud-jpa-sample/inventory/pom.xml new file mode 100644 index 000000000..791892809 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/inventory/pom.xml @@ -0,0 +1,83 @@ + + + + org.seata + seata-springcloud-jpa-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.inventory + inventory-service + 1.0.0-SNAPSHOT + inventory-service + 仓储服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java new file mode 100644 index 000000000..f282968bf --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java @@ -0,0 +1,20 @@ +package com.seata.inventory; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +@EnableJpaRepositories +public class InventoryApplication { + public static void main(String[] args) { + SpringApplication.run(InventoryApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java new file mode 100644 index 000000000..c0bded333 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java @@ -0,0 +1,18 @@ +package com.seata.inventory.controller; + +import com.seata.inventory.service.InventoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class InventoryController { + @Autowired + private InventoryService inventoryService; + + @GetMapping("inventory/deduct") + public void deduct(@RequestParam("commodityCode") String commodityCode , @RequestParam("count") int count) { + inventoryService.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/dao/InventoryDAO.java b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/dao/InventoryDAO.java new file mode 100644 index 000000000..349f5fc7b --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/dao/InventoryDAO.java @@ -0,0 +1,12 @@ +package com.seata.inventory.dao; + +import com.seata.inventory.model.Inventory; + +import org.springframework.data.jpa.repository.JpaRepository; + + +public interface InventoryDAO extends JpaRepository { + + Inventory findByCommodityCode(String commodityCode); + +} diff --git a/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java new file mode 100644 index 000000000..f66ee2219 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java @@ -0,0 +1,25 @@ +package com.seata.inventory.model; + +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; + + +@Entity +@Table(name = "inventory_tbl") +@Data +@DynamicUpdate +@DynamicInsert +public class Inventory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String commodityCode; + + private Integer count; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java new file mode 100644 index 000000000..963b59ee8 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java @@ -0,0 +1,6 @@ +package com.seata.inventory.service; + +public interface InventoryService { + + void deduct(String commodityCode , int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java new file mode 100644 index 000000000..6581b31b9 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java @@ -0,0 +1,27 @@ +package com.seata.inventory.service.impl; + +import com.seata.inventory.dao.InventoryDAO; +import com.seata.inventory.model.Inventory; +import com.seata.inventory.service.InventoryService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class InventoryServiceImpl implements InventoryService { + + @Autowired + private InventoryDAO inventoryDAO; + + + @Override + public void deduct(String commodityCode, int count) { + Inventory inventory = inventoryDAO.findByCommodityCode(commodityCode); + inventory.setCount(inventory.getCount() - count); + inventoryDAO.save(inventory); + + } +} diff --git a/at-sample/seata-springcloud-jpa-sample/inventory/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..7e1f4737e --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/inventory/src/main/resources/bootstrap.yml @@ -0,0 +1,39 @@ +server: + port: 6780 +spring: + application: + name: inventory-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + +eureka: + instance: + instance-id: inventory-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + inventory-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/springcloud-jpa-seata/order-service/pom.xml b/at-sample/seata-springcloud-jpa-sample/order/pom.xml old mode 100755 new mode 100644 similarity index 52% rename from springcloud-jpa-seata/order-service/pom.xml rename to at-sample/seata-springcloud-jpa-sample/order/pom.xml index 4e46b1463..86912ed7e --- a/springcloud-jpa-seata/order-service/pom.xml +++ b/at-sample/seata-springcloud-jpa-sample/order/pom.xml @@ -1,67 +1,84 @@ - - io.seata - springcloud-jpa-seata - 1.1.0 + org.seata + seata-springcloud-jpa-sample + 1.0-SNAPSHOT 4.0.0 - + com.seata.order order-service - jar - + 1.0.0-SNAPSHOT order-service - Demo project for Spring Boot + 订单服务 + + + 1.8 + org.springframework.boot spring-boot-starter-web + + + org.projectlombok + lombok + true + org.springframework.boot spring-boot-starter-test test + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + - mysql - mysql-connector-java - runtime + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + - com.alibaba - druid-spring-boot-starter + io.seata + seata-spring-boot-starter + 1.3.0 + + org.springframework.boot spring-boot-starter-data-jpa + - org.springframework.cloud - spring-cloud-starter-openfeign + mysql + mysql-connector-java + + org.springframework.cloud - spring-cloud-starter-netflix-ribbon - - - com.alibaba.cloud - spring-cloud-alibaba-seata + spring-cloud-starter-openfeign - io.seata - seata-all + io.github.openfeign + feign-okhttp + 10.2.3 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - + \ No newline at end of file diff --git a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/OrderApplication.java b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/OrderApplication.java similarity index 79% rename from springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/OrderApplication.java rename to at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/OrderApplication.java index 5e4af3e87..d385ceae8 100644 --- a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/OrderApplication.java +++ b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/OrderApplication.java @@ -1,15 +1,19 @@ -package io.seata.sample; +package com.seata.order; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + @SpringBootApplication +@EnableDiscoveryClient @EnableFeignClients @EnableJpaRepositories public class OrderApplication { + public static void main(String[] args) { SpringApplication.run(OrderApplication.class, args); } diff --git a/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/controller/OrderController.java b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/controller/OrderController.java new file mode 100644 index 000000000..7a3f1b527 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/controller/OrderController.java @@ -0,0 +1,22 @@ +package com.seata.order.controller; + + +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +public class OrderController { + @Autowired + private OrderService orderService; + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order){ + + return orderService.create(order); + } +} diff --git a/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/dao/OrderDAO.java b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/dao/OrderDAO.java new file mode 100644 index 000000000..35ad210cc --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/dao/OrderDAO.java @@ -0,0 +1,10 @@ +package com.seata.order.dao; + + +import com.seata.order.model.Order; +import org.springframework.data.jpa.repository.JpaRepository; + + +public interface OrderDAO extends JpaRepository { + +} diff --git a/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/model/Order.java b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/model/Order.java new file mode 100644 index 000000000..dd1eb20fc --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/model/Order.java @@ -0,0 +1,33 @@ +package com.seata.order.model; + +import lombok.Data; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.*; + + +@Entity +@Table(name = "order_tbl") +@Data +@DynamicUpdate +@DynamicInsert +public class Order { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(name = "user_id") + private String userId; + + @Column(name = "commodity_code") + private String commodityCode; + + @Column(name = "count") + private Integer count; + + @Column(name = "money") + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/service/OrderService.java b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/service/OrderService.java new file mode 100644 index 000000000..9fb424ee9 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/service/OrderService.java @@ -0,0 +1,10 @@ +package com.seata.order.service; + + +import com.seata.order.model.Order; + + + +public interface OrderService { + boolean create(Order order); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java new file mode 100644 index 000000000..7d7424415 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java @@ -0,0 +1,26 @@ +package com.seata.order.service.impl; + + +import com.seata.order.dao.OrderDAO; +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +@Slf4j +@Service +public class OrderServiceImpl implements OrderService { + + @Autowired + private OrderDAO orderDAO; + + @Override + public boolean create(Order order) { + log.info("创建订单开始"); + orderDAO.save(order); + log.info("创建订单结束"); + return true; + } +} diff --git a/at-sample/seata-springcloud-jpa-sample/order/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-jpa-sample/order/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..95353c6d6 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/order/src/main/resources/bootstrap.yml @@ -0,0 +1,38 @@ +server: + port: 6770 +spring: + application: + name: order-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + +eureka: + instance: + instance-id: order-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + order-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/pom.xml b/at-sample/seata-springcloud-jpa-sample/pom.xml new file mode 100644 index 000000000..9fe35cc7a --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/pom.xml @@ -0,0 +1,57 @@ + + + pom + + inventory + order + account + business + + + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + + + 4.0.0 + + org.seata + seata-springcloud-jpa-sample + 1.0-SNAPSHOT + + + 2.4.2.RELEASE + 1.8 + + + 1.3.0 + + + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR9 + pom + import + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.1.RELEASE + pom + import + + + + + \ No newline at end of file diff --git a/springcloud-jpa-seata/stock-service/pom.xml b/at-sample/seata-springcloud-jpa-sample/seata-server/pom.xml old mode 100755 new mode 100644 similarity index 50% rename from springcloud-jpa-seata/stock-service/pom.xml rename to at-sample/seata-springcloud-jpa-sample/seata-server/pom.xml index d4e3df1b1..decf7b4a6 --- a/springcloud-jpa-seata/stock-service/pom.xml +++ b/at-sample/seata-springcloud-jpa-sample/seata-server/pom.xml @@ -1,63 +1,70 @@ - - io.seata - springcloud-jpa-seata - 1.1.0 + org.seata + seata-springcloud-jpa-sample + 1.0-SNAPSHOT 4.0.0 + com.seata.server + seata-server + 1.0.0-SNAPSHOT + seata-server + seata-server - stock-service - jar - - stock-service - Demo project for Spring Boot + + 1.8 + org.springframework.boot spring-boot-starter-web + + + org.projectlombok + lombok + true + org.springframework.boot spring-boot-starter-test test + + - mysql - mysql-connector-java - runtime + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + - com.alibaba - druid-spring-boot-starter + io.seata + seata-server + 1.5.2 + + + - org.springframework.boot - spring-boot-starter-data-jpa + mysql + mysql-connector-java + + org.springframework.cloud spring-cloud-starter-openfeign - com.alibaba.cloud - spring-cloud-alibaba-seata - - - io.seata - seata-all + io.github.openfeign + feign-okhttp + 10.2.3 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - + \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/seata-server/src/main/java/com/sever/ServerApplication.java b/at-sample/seata-springcloud-jpa-sample/seata-server/src/main/java/com/sever/ServerApplication.java new file mode 100644 index 000000000..4d869d5da --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/seata-server/src/main/java/com/sever/ServerApplication.java @@ -0,0 +1,14 @@ +package com.sever; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.io.IOException; + +@SpringBootApplication(scanBasePackages = {"io.seata"}) +public class ServerApplication { + public static void main(String[] args) throws IOException { + // run the spring-boot application + SpringApplication.run(ServerApplication.class, args); + } +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-jpa-sample/seata-server/src/main/resources/application.yml b/at-sample/seata-springcloud-jpa-sample/seata-server/src/main/resources/application.yml new file mode 100644 index 000000000..807dfc560 --- /dev/null +++ b/at-sample/seata-springcloud-jpa-sample/seata-server/src/main/resources/application.yml @@ -0,0 +1,73 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos, consul, apollo, zk, etcd3 + type: file + + registry: + # support: nacos, eureka, redis, zk, consul, etcd3, sofa + type: eureka + preferred-networks: 30.240.* + eureka: + service-url: http://localhost:8761/eureka + application: default + weight: 1 + + store: + # support: file 、 db 、 redis + mode: db + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druids + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar + user: workshop + password: Workshop123 + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login \ No newline at end of file diff --git a/springcloud-nacos-seata/README.md b/at-sample/seata-springcloud-nacos-sample/README.md similarity index 100% rename from springcloud-nacos-seata/README.md rename to at-sample/seata-springcloud-nacos-sample/README.md diff --git a/at-sample/seata-springcloud-nacos-sample/account/pom.xml b/at-sample/seata-springcloud-nacos-sample/account/pom.xml new file mode 100644 index 000000000..ac4c40b9d --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/account/pom.xml @@ -0,0 +1,91 @@ + + + + seata-springcloud-nacos-sample + io.seata + 1.1.0 + + 4.0.0 + com.seata.account + account-service + 1.0.0-SNAPSHOT + account-service + 账户服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/AccountApplication.java b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/AccountApplication.java new file mode 100644 index 000000000..ecd8b0244 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/AccountApplication.java @@ -0,0 +1,20 @@ +package com.seata.account; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.account.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class AccountApplication { + + + public static void main(String[] args) { + SpringApplication.run(AccountApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/controller/AccountController.java b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/controller/AccountController.java new file mode 100644 index 000000000..53d659e4b --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/controller/AccountController.java @@ -0,0 +1,21 @@ +package com.seata.account.controller; + + +import com.seata.account.service.AccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AccountController { + @Autowired + private AccountService accountService; + + @GetMapping("account/debit") + public void debit(String userId, int money){ + + accountService.debit(userId,money); + }; + +} diff --git a/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java new file mode 100644 index 000000000..1e57aa495 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java @@ -0,0 +1,21 @@ +package com.seata.account.mapper; + + +import com.seata.account.model.Account; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface AccountMapper extends Mapper { + + /** + * 从用户账户中借出 + */ + @Update("update account_tbl set money = money - #{money} where user_id = #{userId}") + void debit(String userId, int money); + +} diff --git a/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/model/Account.java b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/model/Account.java new file mode 100644 index 000000000..f517691dd --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/model/Account.java @@ -0,0 +1,25 @@ +package com.seata.account.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "account_tbl") +@Data +@Accessors(chain = true) +public class Account { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/service/AccountService.java b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/service/AccountService.java new file mode 100644 index 000000000..124c7a3e2 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/service/AccountService.java @@ -0,0 +1,8 @@ +package com.seata.account.service; + + + +public interface AccountService { + + void debit(String userId, int money); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java new file mode 100644 index 000000000..e93d4205f --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java @@ -0,0 +1,24 @@ +package com.seata.account.service.impl; + + +import com.seata.account.mapper.AccountMapper; +import com.seata.account.service.AccountService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + + +@Slf4j +@Service +public class AccountServiceImpl implements AccountService { + + @Autowired + private AccountMapper accountMapper; + + + @Override + public void debit(String userId, int money) { + accountMapper.debit(userId,money); + } +} diff --git a/at-sample/seata-springcloud-nacos-sample/account/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-nacos-sample/account/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..c2fddef5c --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/account/src/main/resources/bootstrap.yml @@ -0,0 +1,53 @@ +server: + port: 6760 +spring: + application: + name: account-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + register-enabled: true + namespace: + config: + server-addr: 127.0.0.1:8848 + enabled: true + file-extension: yaml + namespace: + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + account-service-tx-group: "default" + config: + type: file + # 需要和server在同一个注册中心下 + nacos: + namespace: + serverAddr: 127.0.0.1:8848 + # 需要server端(registry和config)、nacos配置client端(registry和config)保持一致 + group: SEATA_GROUP + username: "nacos" + password: "nacos" + registry: + type: nacos + nacos: + # 需要和server端保持一致,即server在nacos中的名称,默认为seata-server + application: seata-server + server-addr: 127.0.0.1:8848 + group: SEATA_GROUP + namespace: + username: "nacos" + password: "nacos" + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/pom.xml b/at-sample/seata-springcloud-nacos-sample/business/pom.xml similarity index 54% rename from springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/pom.xml rename to at-sample/seata-springcloud-nacos-sample/business/pom.xml index 4edda1551..ccdcff167 100644 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/pom.xml +++ b/at-sample/seata-springcloud-nacos-sample/business/pom.xml @@ -3,66 +3,73 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - springcloud-seata-sharding-jdbc-mybatis-plus-samples + seata-springcloud-nacos-sample io.seata 1.1.0 4.0.0 + com.seata.business + business-service + 1.0.0-SNAPSHOT + business-service - seata-order-sample + + 1.8 + - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - org.springframework.boot spring-boot-starter-web - + - mysql - mysql-connector-java + org.projectlombok + lombok + true - com.baomidou - mybatis-plus-boot-starter - ${mybatis.plus.version} + org.springframework.boot + spring-boot-starter-test + test - + + - org.springframework.cloud - spring-cloud-starter-openfeign + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + com.alibaba.cloud spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + - org.apache.shardingsphere - sharding-jdbc-spring-boot-starter - ${sharding-sphere.version} + io.seata + seata-spring-boot-starter + 1.3.0 + + - org.apache.shardingsphere - sharding-transaction-base-seata-at - ${sharding-sphere.version} + org.springframework.cloud + spring-cloud-starter-openfeign - org.projectlombok - lombok + io.github.openfeign + feign-okhttp + 10.2.3 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/BusinessApplication.java b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/BusinessApplication.java new file mode 100644 index 000000000..856db6ab2 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/BusinessApplication.java @@ -0,0 +1,19 @@ +package com.seata.business; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class BusinessApplication { + + + public static void main(String[] args) { + SpringApplication.run(BusinessApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/AccountClient.java b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/AccountClient.java new file mode 100644 index 000000000..06fd5c85f --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/AccountClient.java @@ -0,0 +1,16 @@ +package com.seata.business.client; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "account-service") +@Component +public interface AccountClient { + + @GetMapping("account/debit") + public void debit(@RequestParam("userId") String userId, @RequestParam("money")int money); + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/InventoryClient.java b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/InventoryClient.java new file mode 100644 index 000000000..d301633c2 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/InventoryClient.java @@ -0,0 +1,19 @@ +package com.seata.business.client; + + + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "inventory-service") +@Component +public interface InventoryClient { + + @GetMapping("inventory/deduct") + public void deduct(@RequestParam("commodityCode") String commodityCode , @RequestParam("count") int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/OrderClient.java b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/OrderClient.java new file mode 100644 index 000000000..259b23750 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/client/OrderClient.java @@ -0,0 +1,18 @@ +package com.seata.business.client; + +import com.seata.business.model.Order; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + + + +@FeignClient(name = "order-service") +@Component +public interface OrderClient { + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order); + +} diff --git a/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/controller/BusinessController.java b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/controller/BusinessController.java new file mode 100644 index 000000000..ba2695825 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/controller/BusinessController.java @@ -0,0 +1,37 @@ +package com.seata.business.controller; + +import com.seata.business.client.AccountClient; +import com.seata.business.client.InventoryClient; +import com.seata.business.client.OrderClient; +import com.seata.business.model.Order; +import io.seata.spring.annotation.GlobalTransactional; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class BusinessController { + @Autowired + private OrderClient orderClient; + @Autowired + private InventoryClient inventoryClient; + @Autowired + private AccountClient accountClient; + + @GetMapping("business/buy") + @GlobalTransactional + public String buy( String userId, String commodityCode, int count){ + int money = count * 1; + accountClient.debit(userId,money); + Order order = new Order(); + order.setUserId(userId); + order.setCommodityCode(commodityCode); + order.setCount(count); + order.setMoney(money); + orderClient.create(order); + inventoryClient.deduct(commodityCode,count); + return "success"; + } + +} diff --git a/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/model/Order.java b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/model/Order.java new file mode 100644 index 000000000..6cba50734 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/business/src/main/java/com/seata/business/model/Order.java @@ -0,0 +1,19 @@ +package com.seata.business.model; + +import lombok.Data; + +@Data +public class Order { + + + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/business/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-nacos-sample/business/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..c9558d901 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/business/src/main/resources/bootstrap.yml @@ -0,0 +1,45 @@ +server: + port: 6750 +spring: + application: + name: business-service + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + register-enabled: true + namespace: + config: + server-addr: 127.0.0.1:8848 + enabled: true + file-extension: yaml + namespace: + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + business-service-tx-group: "default" + config: + type: nacos + # 需要和server在同一个注册中心下 + nacos: + namespace: + serverAddr: 127.0.0.1:8848 + # 需要server端(registry和config)、nacos配置client端(registry和config)保持一致 + group: SEATA_GROUP + username: "nacos" + password: "nacos" + registry: + type: nacos + nacos: + # 需要和server端保持一致,即server在nacos中的名称,默认为seata-server + application: seata-server + server-addr: 127.0.0.1:8848 + group: SEATA_GROUP + namespace: + username: "nacos" + password: "nacos" diff --git a/at-sample/seata-springcloud-nacos-sample/inventory/pom.xml b/at-sample/seata-springcloud-nacos-sample/inventory/pom.xml new file mode 100644 index 000000000..6176fca74 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/inventory/pom.xml @@ -0,0 +1,91 @@ + + + + seata-springcloud-nacos-sample + io.seata + 1.1.0 + + 4.0.0 + com.seata.inventory + inventory-service + 1.0.0-SNAPSHOT + inventory-service + 仓储服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java new file mode 100644 index 000000000..adfad30c6 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java @@ -0,0 +1,21 @@ +package com.seata.inventory; + +// +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.inventory.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class InventoryApplication { + public static void main(String[] args) { + SpringApplication.run(InventoryApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java new file mode 100644 index 000000000..d06a4daf6 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java @@ -0,0 +1,18 @@ +package com.seata.inventory.controller; + +import com.seata.inventory.service.InventoryService; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class InventoryController { + @Autowired + private InventoryService inventoryService; + + @GetMapping("inventory/deduct") + public void deduct(@Param("commodityCode") String commodityCode , @Param("count") int count) { + inventoryService.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/entity/Inventory.java b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/entity/Inventory.java new file mode 100644 index 000000000..4a625496c --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/entity/Inventory.java @@ -0,0 +1,15 @@ +package com.seata.inventory.mapper; + +import com.seata.inventory.model.Inventory; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface InventoryMapper extends Mapper { + + @Update("update inventory_tbl set count = count - #{count} where commodity_code = #{commodityCode}") + void deduct(@Param("commodityCode") String commodityCode , @Param("count") int count); +} diff --git a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/repository/StockDAO.java b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java similarity index 100% rename from springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/repository/StockDAO.java rename to at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java diff --git a/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java new file mode 100644 index 000000000..963b59ee8 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java @@ -0,0 +1,6 @@ +package com.seata.inventory.service; + +public interface InventoryService { + + void deduct(String commodityCode , int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java new file mode 100644 index 000000000..65ff61364 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java @@ -0,0 +1,23 @@ +package com.seata.inventory.service.impl; + +import com.seata.inventory.mapper.InventoryMapper; +import com.seata.inventory.service.InventoryService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class InventoryServiceImpl implements InventoryService { + + @Autowired + private InventoryMapper inventoryMapper; + + + @Override + public void deduct(String commodityCode, int count) { + inventoryMapper.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-nacos-sample/inventory/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..b4889fc47 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/inventory/src/main/resources/bootstrap.yml @@ -0,0 +1,53 @@ +server: + port: 6780 +spring: + application: + name: inventory-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + register-enabled: true + namespace: + config: + server-addr: 127.0.0.1:8848 + enabled: true + file-extension: yaml + namespace: + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + inventory-service-tx-group: "default" + config: + type: nacos + # 需要和server在同一个注册中心下 + nacos: + namespace: + serverAddr: 127.0.0.1:8848 + # 需要server端(registry和config)、nacos配置client端(registry和config)保持一致 + group: SEATA_GROUP + username: "nacos" + password: "nacos" + registry: + type: nacos + nacos: + # 需要和server端保持一致,即server在nacos中的名称,默认为seata-server + application: seata-server + server-addr: 127.0.0.1:8848 + group: SEATA_GROUP + namespace: + username: "nacos" + password: "nacos" + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/order/pom.xml b/at-sample/seata-springcloud-nacos-sample/order/pom.xml new file mode 100644 index 000000000..98db38d47 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/order/pom.xml @@ -0,0 +1,91 @@ + + + + seata-springcloud-nacos-sample + io.seata + 1.1.0 + + 4.0.0 + com.seata.order + order-service + 1.0.0-SNAPSHOT + order-service + 订单服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/OrderApplication.java b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/OrderApplication.java new file mode 100644 index 000000000..1cb0eb485 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/OrderApplication.java @@ -0,0 +1,20 @@ +package com.seata.order; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.order.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class OrderApplication { + + + public static void main(String[] args) { + SpringApplication.run(OrderApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/controller/OrderController.java b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/controller/OrderController.java new file mode 100644 index 000000000..1b876ef47 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/controller/OrderController.java @@ -0,0 +1,23 @@ +package com.seata.order.controller; + + +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; + +@RestController +public class OrderController { + @Autowired + private OrderService orderService; + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order){ + + return orderService.create(order); + } +} diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/feign/AccountFeignClient.java b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/feign/AccountFeignClient.java similarity index 100% rename from springcloud-nacos-seata/order-service/src/main/java/com/work/order/feign/AccountFeignClient.java rename to at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/feign/AccountFeignClient.java diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/feign/StockFeignClient.java b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/feign/StockFeignClient.java similarity index 100% rename from springcloud-nacos-seata/order-service/src/main/java/com/work/order/feign/StockFeignClient.java rename to at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/feign/StockFeignClient.java diff --git a/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java new file mode 100644 index 000000000..902a3265e --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java @@ -0,0 +1,13 @@ +package com.seata.order.mapper; + + +import com.seata.order.model.Order; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface OrderMapper extends Mapper { + +} + diff --git a/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/model/Order.java b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/model/Order.java new file mode 100644 index 000000000..9200efc82 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/model/Order.java @@ -0,0 +1,29 @@ +package com.seata.order.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "order_tbl") +@Data +@Accessors(chain = true) +public class Order { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/service/OrderService.java b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/service/OrderService.java new file mode 100644 index 000000000..d85651465 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/service/OrderService.java @@ -0,0 +1,8 @@ +package com.seata.order.service; + +import com.seata.order.model.Order; + +public interface OrderService { + + boolean create(Order order); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java new file mode 100644 index 000000000..5d3e2632d --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java @@ -0,0 +1,27 @@ +package com.seata.order.service.impl; + + +import com.seata.order.mapper.OrderMapper; +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class OrderServiceImpl implements OrderService { + + @Autowired + private OrderMapper orderMapper; + + @Override + public boolean create(Order order) { + log.info("创建订单开始"); + int index = orderMapper.insert(order); + log.info("创建订单结束"); + return index > 0; + } +} diff --git a/at-sample/seata-springcloud-nacos-sample/order/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-nacos-sample/order/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..1337a8025 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/order/src/main/resources/bootstrap.yml @@ -0,0 +1,53 @@ +server: + port: 6770 +spring: + application: + name: order-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + cloud: + nacos: + discovery: + server-addr: 127.0.0.1:8848 + register-enabled: true + namespace: + config: + server-addr: 127.0.0.1:8848 + enabled: true + file-extension: yaml + namespace: + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + order-service-tx-group: "default" + config: + type: nacos + # 需要和server在同一个注册中心下 + nacos: + namespace: + serverAddr: 127.0.0.1:8848 + # 需要server端(registry和config)、nacos配置client端(registry和config)保持一致 + group: SEATA_GROUP + username: "nacos" + password: "nacos" + registry: + type: nacos + nacos: + # 需要和server端保持一致,即server在nacos中的名称,默认为seata-server + application: seata-server + server-addr: 127.0.0.1:8848 + group: SEATA_GROUP + namespace: + username: "nacos" + password: "nacos" + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/pom.xml b/at-sample/seata-springcloud-nacos-sample/pom.xml similarity index 54% rename from springcloud-seata-sharding-jdbc-mybatis-plus-samples/pom.xml rename to at-sample/seata-springcloud-nacos-sample/pom.xml index 9d276c56e..209b77866 100644 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/pom.xml +++ b/at-sample/seata-springcloud-nacos-sample/pom.xml @@ -2,54 +2,61 @@ - - 4.0.0 - - springcloud-seata-sharding-jdbc-mybatis-plus-samples pom - seata-order-sample - seata-product-sample + inventory + order + account + business - io.seata - 1.1.0 - - org.springframework.boot spring-boot-starter-parent - 2.3.5.RELEASE + 2.3.2.RELEASE + 4.0.0 + + io.seata + seata-springcloud-nacos-sample + 1.1.0 - - HHmmss - UTF-8 - UTF-8 + 2.4.2.RELEASE 1.8 - Hoxton.SR9 - 2.2.5.RELEASE - 3.4.1 - 4.1.1 + 2.1.5 + 4.1.5 + 1.3.0 - - + + + tk.mybatis + mapper-spring-boot-starter + ${mybatis.version} + + + tk.mybatis + mapper + ${tk-mapper.version} + + + org.springframework.cloud spring-cloud-dependencies - ${spring-cloud.version} + Hoxton.SR9 pom import - + + com.alibaba.cloud spring-cloud-alibaba-dependencies - ${spring-cloud-alibaba.version} + 2.2.1.RELEASE pom import diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/pom.xml b/at-sample/seata-springcloud-nacos-sample/seata-server/pom.xml similarity index 58% rename from springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/pom.xml rename to at-sample/seata-springcloud-nacos-sample/seata-server/pom.xml index a3d392941..7218f7d20 100644 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/pom.xml +++ b/at-sample/seata-springcloud-nacos-sample/seata-server/pom.xml @@ -3,61 +3,71 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - springcloud-seata-sharding-jdbc-mybatis-plus-samples io.seata + seata-springcloud-nacos-sample 1.1.0 4.0.0 + com.seata.server + seata-server + 1.0.0-SNAPSHOT + seata-server + seata-server - seata-product-sample + + 1.8 + - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - org.springframework.boot spring-boot-starter-web - + - mysql - mysql-connector-java + org.projectlombok + lombok + true - com.baomidou - mybatis-plus-boot-starter - ${mybatis.plus.version} + org.springframework.boot + spring-boot-starter-test + test - + + - org.springframework.cloud - spring-cloud-starter-openfeign + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud - spring-cloud-starter-alibaba-seata + spring-cloud-starter-alibaba-nacos-config + + - org.apache.shardingsphere - sharding-transaction-base-seata-at - ${sharding-sphere.version} + io.seata + seata-server + 1.5.2 + + - org.projectlombok - lombok + mysql + mysql-connector-java - - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/seata-server/src/main/java/com/sever/ServerApplication.java b/at-sample/seata-springcloud-nacos-sample/seata-server/src/main/java/com/sever/ServerApplication.java new file mode 100644 index 000000000..fdb90b453 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/seata-server/src/main/java/com/sever/ServerApplication.java @@ -0,0 +1,14 @@ +package com.sever; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.io.IOException; + +@SpringBootApplication +public class ServerApplication { + public static void main(String[] args) throws IOException { + // run the spring-boot application + SpringApplication.run(ServerApplication.class, args); + } +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-nacos-sample/seata-server/src/main/resources/application.yml b/at-sample/seata-springcloud-nacos-sample/seata-server/src/main/resources/application.yml new file mode 100644 index 000000000..98c06d233 --- /dev/null +++ b/at-sample/seata-springcloud-nacos-sample/seata-server/src/main/resources/application.yml @@ -0,0 +1,90 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos, consul, apollo, zk, etcd3 + type: nacos + nacos: + server-addr: 127.0.0.1:8848 + namespace: + group: SEATA_GROUP + username: nacos + password: nacos + ##if use MSE Nacos with auth, mutex with username/password attribute + #access-key: "" + #secret-key: "" + data-id: seataServer.properties + registry: + # support: nacos, eureka, redis, zk, consul, etcd3, sofa + type: nacos + preferred-networks: 30.240.* + nacos: + application: seata-server + server-addr: 127.0.0.1:8848 + group: SEATA_GROUP + namespace: + cluster: default + username: nacos + password: nacos + ##if use MSE Nacos with auth, mutex with username/password attribute + #access-key: "" + #secret-key: "" + server: + service-port: 8091 + store: + # support: file 、 db 、 redis + mode: db + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druids + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/seata + user: root + password: root + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 +# server: +# service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login \ No newline at end of file diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/README.md b/at-sample/seata-springcloud-sharding-jdbc-sample/README.md similarity index 100% rename from springcloud-seata-sharding-jdbc-mybatis-plus-samples/README.md rename to at-sample/seata-springcloud-sharding-jdbc-sample/README.md diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/account/pom.xml b/at-sample/seata-springcloud-sharding-jdbc-sample/account/pom.xml new file mode 100644 index 000000000..3c40134be --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/account/pom.xml @@ -0,0 +1,88 @@ + + + + org.seata + seata-springcloud-sharding-jdbc-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.account + account-service + 1.0.0-SNAPSHOT + account-service + 账户服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/AccountApplication.java b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/AccountApplication.java new file mode 100644 index 000000000..ecd8b0244 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/AccountApplication.java @@ -0,0 +1,20 @@ +package com.seata.account; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.account.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class AccountApplication { + + + public static void main(String[] args) { + SpringApplication.run(AccountApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/controller/AccountController.java b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/controller/AccountController.java new file mode 100644 index 000000000..53d659e4b --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/controller/AccountController.java @@ -0,0 +1,21 @@ +package com.seata.account.controller; + + +import com.seata.account.service.AccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class AccountController { + @Autowired + private AccountService accountService; + + @GetMapping("account/debit") + public void debit(String userId, int money){ + + accountService.debit(userId,money); + }; + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java new file mode 100644 index 000000000..1e57aa495 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/mapper/AccountMapper.java @@ -0,0 +1,21 @@ +package com.seata.account.mapper; + + +import com.seata.account.model.Account; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface AccountMapper extends Mapper { + + /** + * 从用户账户中借出 + */ + @Update("update account_tbl set money = money - #{money} where user_id = #{userId}") + void debit(String userId, int money); + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/model/Account.java b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/model/Account.java new file mode 100644 index 000000000..f517691dd --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/model/Account.java @@ -0,0 +1,25 @@ +package com.seata.account.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "account_tbl") +@Data +@Accessors(chain = true) +public class Account { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/service/AccountService.java b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/service/AccountService.java new file mode 100644 index 000000000..124c7a3e2 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/service/AccountService.java @@ -0,0 +1,8 @@ +package com.seata.account.service; + + + +public interface AccountService { + + void debit(String userId, int money); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java new file mode 100644 index 000000000..e93d4205f --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/java/com/seata/account/service/impl/AccountServiceImpl.java @@ -0,0 +1,24 @@ +package com.seata.account.service.impl; + + +import com.seata.account.mapper.AccountMapper; +import com.seata.account.service.AccountService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + + +@Slf4j +@Service +public class AccountServiceImpl implements AccountService { + + @Autowired + private AccountMapper accountMapper; + + + @Override + public void debit(String userId, int money) { + accountMapper.debit(userId,money); + } +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..1395de660 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/account/src/main/resources/bootstrap.yml @@ -0,0 +1,38 @@ +server: + port: 6760 +spring: + application: + name: account-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + +eureka: + instance: + instance-id: account-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + account-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/business/pom.xml b/at-sample/seata-springcloud-sharding-jdbc-sample/business/pom.xml new file mode 100644 index 000000000..481378faa --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/business/pom.xml @@ -0,0 +1,79 @@ + + + + org.seata + seata-springcloud-sharding-jdbc-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.business + business-service + 1.0.0-SNAPSHOT + business-service + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + + org.apache.shardingsphere + sharding-transaction-base-seata-at + 4.1.1 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/BusinessApplication.java b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/BusinessApplication.java new file mode 100644 index 000000000..856db6ab2 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/BusinessApplication.java @@ -0,0 +1,19 @@ +package com.seata.business; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class BusinessApplication { + + + public static void main(String[] args) { + SpringApplication.run(BusinessApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/AccountClient.java b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/AccountClient.java new file mode 100644 index 000000000..06fd5c85f --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/AccountClient.java @@ -0,0 +1,16 @@ +package com.seata.business.client; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "account-service") +@Component +public interface AccountClient { + + @GetMapping("account/debit") + public void debit(@RequestParam("userId") String userId, @RequestParam("money")int money); + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/InventoryClient.java b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/InventoryClient.java new file mode 100644 index 000000000..d301633c2 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/InventoryClient.java @@ -0,0 +1,19 @@ +package com.seata.business.client; + + + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + + +@FeignClient(name = "inventory-service") +@Component +public interface InventoryClient { + + @GetMapping("inventory/deduct") + public void deduct(@RequestParam("commodityCode") String commodityCode , @RequestParam("count") int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/OrderClient.java b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/OrderClient.java new file mode 100644 index 000000000..259b23750 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/client/OrderClient.java @@ -0,0 +1,18 @@ +package com.seata.business.client; + +import com.seata.business.model.Order; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + + + +@FeignClient(name = "order-service") +@Component +public interface OrderClient { + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order); + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/controller/BusinessController.java b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/controller/BusinessController.java new file mode 100644 index 000000000..36fb7379e --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/controller/BusinessController.java @@ -0,0 +1,40 @@ +package com.seata.business.controller; + +import com.seata.business.client.AccountClient; +import com.seata.business.client.InventoryClient; +import com.seata.business.client.OrderClient; +import com.seata.business.model.Order; +import io.seata.spring.annotation.GlobalTransactional; +import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType; +import org.apache.shardingsphere.transaction.core.TransactionType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class BusinessController { + @Autowired + private OrderClient orderClient; + @Autowired + private InventoryClient inventoryClient; + @Autowired + private AccountClient accountClient; + + //这里切记不要加@GlobalTransactional + @GetMapping("business/buy") + @ShardingTransactionType(TransactionType.BASE) + public String buy( String userId, String commodityCode, int count){ + int money = count * 1; + accountClient.debit(userId,money); + Order order = new Order(); + order.setUserId(userId); + order.setCommodityCode(commodityCode); + order.setCount(count); + order.setMoney(money); + orderClient.create(order); + inventoryClient.deduct(commodityCode,count); + return "success"; + } + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/model/Order.java b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/model/Order.java new file mode 100644 index 000000000..6cba50734 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/java/com/seata/business/model/Order.java @@ -0,0 +1,19 @@ +package com.seata.business.model; + +import lombok.Data; + +@Data +public class Order { + + + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..d94a952fd --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/business/src/main/resources/bootstrap.yml @@ -0,0 +1,29 @@ +server: + port: 6750 +spring: + application: + name: business-service +eureka: + instance: + instance-id: business-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + business-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + eight: 1 \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/pom.xml b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/pom.xml new file mode 100644 index 000000000..f8a8e7fbc --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/pom.xml @@ -0,0 +1,87 @@ + + + + org.seata + seata-springcloud-sharding-jdbc-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.inventory + inventory-service + 1.0.0-SNAPSHOT + inventory-service + 仓储服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java new file mode 100644 index 000000000..adfad30c6 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/InventoryApplication.java @@ -0,0 +1,21 @@ +package com.seata.inventory; + +// +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.inventory.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class InventoryApplication { + public static void main(String[] args) { + SpringApplication.run(InventoryApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java new file mode 100644 index 000000000..d06a4daf6 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/controller/InventoryController.java @@ -0,0 +1,18 @@ +package com.seata.inventory.controller; + +import com.seata.inventory.service.InventoryService; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class InventoryController { + @Autowired + private InventoryService inventoryService; + + @GetMapping("inventory/deduct") + public void deduct(@Param("commodityCode") String commodityCode , @Param("count") int count) { + inventoryService.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java new file mode 100644 index 000000000..4a625496c --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/mapper/InventoryMapper.java @@ -0,0 +1,15 @@ +package com.seata.inventory.mapper; + +import com.seata.inventory.model.Inventory; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface InventoryMapper extends Mapper { + + @Update("update inventory_tbl set count = count - #{count} where commodity_code = #{commodityCode}") + void deduct(@Param("commodityCode") String commodityCode , @Param("count") int count); +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java new file mode 100644 index 000000000..51635196e --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/model/Inventory.java @@ -0,0 +1,25 @@ +package com.seata.inventory.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "inventory_tbl") +@Data +@Accessors(chain = true) +public class Inventory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String commodityCode; + + private Integer count; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java new file mode 100644 index 000000000..963b59ee8 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/service/InventoryService.java @@ -0,0 +1,6 @@ +package com.seata.inventory.service; + +public interface InventoryService { + + void deduct(String commodityCode , int count); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java new file mode 100644 index 000000000..65ff61364 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/java/com/seata/inventory/service/impl/InventoryServiceImpl.java @@ -0,0 +1,23 @@ +package com.seata.inventory.service.impl; + +import com.seata.inventory.mapper.InventoryMapper; +import com.seata.inventory.service.InventoryService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class InventoryServiceImpl implements InventoryService { + + @Autowired + private InventoryMapper inventoryMapper; + + + @Override + public void deduct(String commodityCode, int count) { + inventoryMapper.deduct(commodityCode,count); + } +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..7e1f4737e --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/inventory/src/main/resources/bootstrap.yml @@ -0,0 +1,39 @@ +server: + port: 6780 +spring: + application: + name: inventory-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + +eureka: + instance: + instance-id: inventory-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + inventory-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/pom.xml b/at-sample/seata-springcloud-sharding-jdbc-sample/order/pom.xml new file mode 100644 index 000000000..4998bc657 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/pom.xml @@ -0,0 +1,102 @@ + + + + org.seata + seata-springcloud-sharding-jdbc-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.order + order-service + 1.0.0-SNAPSHOT + order-service + 订单服务 + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + org.apache.shardingsphere + sharding-jdbc-spring-boot-starter + 4.1.1 + + + + org.apache.shardingsphere + sharding-transaction-base-seata-at + 4.1.1 + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-seata + + + io.seata + seata-spring-boot-starter + + + + + io.seata + seata-spring-boot-starter + 1.3.0 + + + + + tk.mybatis + mapper-spring-boot-starter + + + tk.mybatis + mapper + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/OrderApplication.java b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/OrderApplication.java new file mode 100644 index 000000000..1cb0eb485 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/OrderApplication.java @@ -0,0 +1,20 @@ +package com.seata.order; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import tk.mybatis.spring.annotation.MapperScan; + +@SpringBootApplication +@MapperScan("com.seata.order.mapper") +@EnableDiscoveryClient +@EnableFeignClients +public class OrderApplication { + + + public static void main(String[] args) { + SpringApplication.run(OrderApplication.class, args); + } + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/controller/OrderController.java b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/controller/OrderController.java new file mode 100644 index 000000000..1b876ef47 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/controller/OrderController.java @@ -0,0 +1,23 @@ +package com.seata.order.controller; + + +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; + +@RestController +public class OrderController { + @Autowired + private OrderService orderService; + + @PostMapping("order/create") + public Boolean create(@RequestBody Order order){ + + return orderService.create(order); + } +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java new file mode 100644 index 000000000..fc3a21ee6 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/mapper/OrderMapper.java @@ -0,0 +1,12 @@ +package com.seata.order.mapper; + + +import com.seata.order.model.Order; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + + +@Repository +public interface OrderMapper extends Mapper { + +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/model/Order.java b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/model/Order.java new file mode 100644 index 000000000..9200efc82 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/model/Order.java @@ -0,0 +1,29 @@ +package com.seata.order.model; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Table(name = "order_tbl") +@Data +@Accessors(chain = true) +public class Order { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String userId; + + private String commodityCode; + + private Integer count; + + private Integer money; + +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/service/OrderService.java b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/service/OrderService.java new file mode 100644 index 000000000..d85651465 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/service/OrderService.java @@ -0,0 +1,8 @@ +package com.seata.order.service; + +import com.seata.order.model.Order; + +public interface OrderService { + + boolean create(Order order); +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java new file mode 100644 index 000000000..5d3e2632d --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/java/com/seata/order/service/impl/OrderServiceImpl.java @@ -0,0 +1,27 @@ +package com.seata.order.service.impl; + + +import com.seata.order.mapper.OrderMapper; +import com.seata.order.model.Order; +import com.seata.order.service.OrderService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Slf4j +@Service +public class OrderServiceImpl implements OrderService { + + @Autowired + private OrderMapper orderMapper; + + @Override + public boolean create(Order order) { + log.info("创建订单开始"); + int index = orderMapper.insert(order); + log.info("创建订单结束"); + return index > 0; + } +} diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/resources/bootstrap.yml b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/resources/bootstrap.yml new file mode 100644 index 000000000..0954ef413 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/resources/bootstrap.yml @@ -0,0 +1,82 @@ +server: + port: 6770 +spring: + application: + name: order-service + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root + url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + + shardingsphere: + datasource: + names: ds0,ds1 + ds0: + driver-class-name: com.mysql.cj.jdbc.Driver + jdbc-url: jdbc:mysql://127.0.0.1:3306/seata_samples?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8 + password: root + type: com.zaxxer.hikari.HikariDataSource + username: root + ds1: + driver-class-name: com.mysql.jdbc.Driver + jdbc-url: jdbc:mysql://192.168.71.129:3306/seata_samples + password: root + type: com.zaxxer.hikari.HikariDataSource + username: root + + props: + sql-show: true + rules: + sharding: + key-generators: + snowflake: + props: + worker-id: 666 + type: SNOWFLAKE + sharding-algorithms: + database-inline: + props: + algorithm-expression: ds$->{id % 3} + type: INLINE + tables: + order_tbl: + database-strategy: + standard: + sharding-algorithm-name: database-inline + sharding-column: id + key-generate-strategy: + column: id + sharding: + default-key-generate-strategy: + xxx: snowflake + +eureka: + instance: + instance-id: order-service + prefer-ip-address: true + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://127.0.0.1:8761/eureka + +seata: + enabled: true + application-id: ${spring.application.name} + # 事务群组(可以每个应用独立取名,也可以使用相同的名字),要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 + tx-service-group: ${spring.application.name}-tx-group + service: + vgroup-mapping: + order-service-tx-group: "default" + + registry: + type: eureka + eureka: + service-url: http://localhost:8761/eureka + weight: 1 + +mybatis: + mapperLocations: classpath:mapper/*.xml + + diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/resources/seata.conf b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/resources/seata.conf new file mode 100644 index 000000000..b545e9367 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/order/src/main/resources/seata.conf @@ -0,0 +1,4 @@ +client { + application.id = order-service + transaction.service.group = order-service-tx-group +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/pom.xml b/at-sample/seata-springcloud-sharding-jdbc-sample/pom.xml new file mode 100644 index 000000000..1efb57888 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/pom.xml @@ -0,0 +1,66 @@ + + + pom + + inventory + order + account + business + + + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + + + 4.0.0 + + org.seata + seata-springcloud-sharding-jdbc-sample + 1.0-SNAPSHOT + + + 2.4.2.RELEASE + 1.8 + 2.1.5 + 4.1.5 + 1.3.0 + + + + + + + tk.mybatis + mapper-spring-boot-starter + ${mybatis.version} + + + tk.mybatis + mapper + ${tk-mapper.version} + + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR9 + pom + import + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.1.RELEASE + pom + import + + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/pom.xml b/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/pom.xml new file mode 100644 index 000000000..327f9ac69 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/pom.xml @@ -0,0 +1,70 @@ + + + + org.seata + seata-springcloud-sharding-jdbc-sample + 1.0-SNAPSHOT + + 4.0.0 + com.seata.server + seata-server + 1.0.0-SNAPSHOT + seata-server + seata-server + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + io.seata + seata-server + 1.5.2 + + + + + + mysql + mysql-connector-java + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + io.github.openfeign + feign-okhttp + 10.2.3 + + + + \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/src/main/java/com/sever/ServerApplication.java b/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/src/main/java/com/sever/ServerApplication.java new file mode 100644 index 000000000..4d869d5da --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/src/main/java/com/sever/ServerApplication.java @@ -0,0 +1,14 @@ +package com.sever; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.io.IOException; + +@SpringBootApplication(scanBasePackages = {"io.seata"}) +public class ServerApplication { + public static void main(String[] args) throws IOException { + // run the spring-boot application + SpringApplication.run(ServerApplication.class, args); + } +} \ No newline at end of file diff --git a/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/src/main/resources/application.yml b/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/src/main/resources/application.yml new file mode 100644 index 000000000..807dfc560 --- /dev/null +++ b/at-sample/seata-springcloud-sharding-jdbc-sample/seata-server/src/main/resources/application.yml @@ -0,0 +1,73 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos, consul, apollo, zk, etcd3 + type: file + + registry: + # support: nacos, eureka, redis, zk, consul, etcd3, sofa + type: eureka + preferred-networks: 30.240.* + eureka: + service-url: http://localhost:8761/eureka + application: default + weight: 1 + + store: + # support: file 、 db 、 redis + mode: db + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druids + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar + user: workshop + password: Workshop123 + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login \ No newline at end of file diff --git a/pom.xml b/pom.xml index 90d203fb9..c95e0e60b 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,12 @@ dubbo + seata-server-deploy + at-sample + tcc-sample + saga-sample + xa-sample + seata-best-practices diff --git a/saga-sample/pom.xml b/saga-sample/pom.xml new file mode 100644 index 000000000..d32dc3e3e --- /dev/null +++ b/saga-sample/pom.xml @@ -0,0 +1,19 @@ + + + + seata-samples + io.seata + 1.1.0 + + 4.0.0 + + saga-sample + + + 8 + 8 + + + \ No newline at end of file diff --git a/seata-best-practices/pom.xml b/seata-best-practices/pom.xml new file mode 100644 index 000000000..f7b0530cd --- /dev/null +++ b/seata-best-practices/pom.xml @@ -0,0 +1,19 @@ + + + + seata-samples + io.seata + 1.1.0 + + 4.0.0 + + seata-best-practices + + + 8 + 8 + + + \ No newline at end of file diff --git a/seata-server-deploy/file-depoly/pom.xml b/seata-server-deploy/file-depoly/pom.xml new file mode 100644 index 000000000..d3d9a11e9 --- /dev/null +++ b/seata-server-deploy/file-depoly/pom.xml @@ -0,0 +1,19 @@ + + + + seata-server-deploy + io.seata + 1.1.0 + + 4.0.0 + + file-depoly + + + 8 + 8 + + + \ No newline at end of file diff --git a/seata-server-deploy/file-depoly/src/main/resources/application.yml b/seata-server-deploy/file-depoly/src/main/resources/application.yml new file mode 100644 index 000000000..b7971f4a0 --- /dev/null +++ b/seata-server-deploy/file-depoly/src/main/resources/application.yml @@ -0,0 +1,40 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos, consul, apollo, zk, etcd3 + type: file + registry: + # support: nacos, eureka, redis, zk, consul, etcd3, sofa + type: file + store: + # support: file 、 db 、 redis + mode: file +# server: +# service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-consul/pom.xml b/seata-server-deploy/ha/ha-consul/pom.xml new file mode 100644 index 000000000..008024c9d --- /dev/null +++ b/seata-server-deploy/ha/ha-consul/pom.xml @@ -0,0 +1,19 @@ + + + + ha + io.seata + 1.1.0 + + 4.0.0 + + ha-consul + + + 8 + 8 + + + \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-consul/src/main/resources/application.yml b/seata-server-deploy/ha/ha-consul/src/main/resources/application.yml new file mode 100644 index 000000000..82e5a5cbc --- /dev/null +++ b/seata-server-deploy/ha/ha-consul/src/main/resources/application.yml @@ -0,0 +1,89 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos 、 consul 、 apollo 、 zk 、 etcd3 + type: consul + consul: + server-addr: 127.0.0.1:8500 + acl-token: + key: seata.properties + registry: + # support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa + type: consul + preferred-networks: 30.240.* + consul: + cluster: default + server-addr: 127.0.0.1:8500 + acl-token: + store: + # support: file 、 db 、 redis + mode: db + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druid + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true + user: mysql + password: mysql + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 + redis: + mode: single + database: 0 + min-conn: 1 + max-conn: 10 + password: + max-total: 100 + query-limit: 100 + single: + host: 127.0.0.1 + port: 6379 + sentinel: + master-name: + sentinel-hosts: + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login diff --git a/seata-server-deploy/ha/ha-consul/src/main/resources/db/mysql.sql b/seata-server-deploy/ha/ha-consul/src/main/resources/db/mysql.sql new file mode 100644 index 000000000..d401e1345 --- /dev/null +++ b/seata-server-deploy/ha/ha-consul/src/main/resources/db/mysql.sql @@ -0,0 +1,73 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS `global_table` +( + `xid` VARCHAR(128) NOT NULL, + `transaction_id` BIGINT, + `status` TINYINT NOT NULL, + `application_id` VARCHAR(32), + `transaction_service_group` VARCHAR(32), + `transaction_name` VARCHAR(128), + `timeout` INT, + `begin_time` BIGINT, + `application_data` VARCHAR(2000), + `gmt_create` DATETIME, + `gmt_modified` DATETIME, + PRIMARY KEY (`xid`), + KEY `idx_status_gmt_modified` (`status` , `gmt_modified`), + KEY `idx_transaction_id` (`transaction_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS `branch_table` +( + `branch_id` BIGINT NOT NULL, + `xid` VARCHAR(128) NOT NULL, + `transaction_id` BIGINT, + `resource_group_id` VARCHAR(32), + `resource_id` VARCHAR(256), + `branch_type` VARCHAR(8), + `status` TINYINT, + `client_id` VARCHAR(64), + `application_data` VARCHAR(2000), + `gmt_create` DATETIME(6), + `gmt_modified` DATETIME(6), + PRIMARY KEY (`branch_id`), + KEY `idx_xid` (`xid`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS `lock_table` +( + `row_key` VARCHAR(128) NOT NULL, + `xid` VARCHAR(128), + `transaction_id` BIGINT, + `branch_id` BIGINT NOT NULL, + `resource_id` VARCHAR(256), + `table_name` VARCHAR(32), + `pk` VARCHAR(36), + `status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking', + `gmt_create` DATETIME, + `gmt_modified` DATETIME, + PRIMARY KEY (`row_key`), + KEY `idx_status` (`status`), + KEY `idx_branch_id` (`branch_id`), + KEY `idx_xid_and_branch_id` (`xid` , `branch_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +CREATE TABLE IF NOT EXISTS `distributed_lock` +( + `lock_key` CHAR(20) NOT NULL, + `lock_value` VARCHAR(20) NOT NULL, + `expire` BIGINT, + primary key (`lock_key`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-consul/src/main/resources/db/oracle.sql b/seata-server-deploy/ha/ha-consul/src/main/resources/db/oracle.sql new file mode 100644 index 000000000..437019a4d --- /dev/null +++ b/seata-server-deploy/ha/ha-consul/src/main/resources/db/oracle.sql @@ -0,0 +1,72 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE global_table +( + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + status NUMBER(3) NOT NULL, + application_id VARCHAR2(32), + transaction_service_group VARCHAR2(32), + transaction_name VARCHAR2(128), + timeout NUMBER(10), + begin_time NUMBER(19), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE branch_table +( + branch_id NUMBER(19) NOT NULL, + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + resource_group_id VARCHAR2(32), + resource_id VARCHAR2(256), + branch_type VARCHAR2(8), + status NUMBER(3), + client_id VARCHAR2(64), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON branch_table (xid); + +-- the table to store lock data +CREATE TABLE lock_table +( + row_key VARCHAR2(128) NOT NULL, + xid VARCHAR2(128), + transaction_id NUMBER(19), + branch_id NUMBER(19) NOT NULL, + resource_id VARCHAR2(256), + table_name VARCHAR2(32), + pk VARCHAR2(36), + status NUMBER(3) NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (row_key) +); + +comment on column lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON lock_table (branch_id); +CREATE INDEX idx_xid_and_branch_id ON lock_table (xid, branch_id); +CREATE INDEX idx_status ON lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR2(20) NOT NULL, + lock_value VARCHAR2(20) NOT NULL, + expire DECIMAL(18) NOT NULL, + PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); diff --git a/seata-server-deploy/ha/ha-consul/src/main/resources/db/postgresql.sql b/seata-server-deploy/ha/ha-consul/src/main/resources/db/postgresql.sql new file mode 100644 index 000000000..f4727ef45 --- /dev/null +++ b/seata-server-deploy/ha/ha-consul/src/main/resources/db/postgresql.sql @@ -0,0 +1,72 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS public.global_table +( + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + status SMALLINT NOT NULL, + application_id VARCHAR(32), + transaction_service_group VARCHAR(32), + transaction_name VARCHAR(128), + timeout INT, + begin_time BIGINT, + application_data VARCHAR(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_global_table PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON public.global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON public.global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS public.branch_table +( + branch_id BIGINT NOT NULL, + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + resource_group_id VARCHAR(32), + resource_id VARCHAR(256), + branch_type VARCHAR(8), + status SMALLINT, + client_id VARCHAR(64), + application_data VARCHAR(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + CONSTRAINT pk_branch_table PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON public.branch_table (xid); + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS public.lock_table +( + row_key VARCHAR(128) NOT NULL, + xid VARCHAR(128), + transaction_id BIGINT, + branch_id BIGINT NOT NULL, + resource_id VARCHAR(256), + table_name VARCHAR(32), + pk VARCHAR(36), + status SMALLINT NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_lock_table PRIMARY KEY (row_key) +); + +comment on column public.lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON public.lock_table (branch_id); +CREATE INDEX idx_xid_and_branch_id ON public.lock_table (xid, branch_id); +CREATE INDEX idx_status ON public.lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR(20) NOT NULL, + lock_value VARCHAR(20) NOT NULL, + expire BIGINT NOT NULL, + CONSTRAINT pk_distributed_lock_table PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); diff --git a/seata-server-deploy/ha/ha-erueka/pom.xml b/seata-server-deploy/ha/ha-erueka/pom.xml new file mode 100644 index 000000000..0f0880237 --- /dev/null +++ b/seata-server-deploy/ha/ha-erueka/pom.xml @@ -0,0 +1,19 @@ + + + + ha + io.seata + 1.1.0 + + 4.0.0 + + ha-erueka + + + 8 + 8 + + + \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-erueka/src/main/resources/application.yml b/seata-server-deploy/ha/ha-erueka/src/main/resources/application.yml new file mode 100644 index 000000000..0b2738935 --- /dev/null +++ b/seata-server-deploy/ha/ha-erueka/src/main/resources/application.yml @@ -0,0 +1,92 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos 、 consul 、 apollo 、 zk 、 etcd3 + type: apollo + apollo: + appId: seata-server + apollo-meta: http://192.168.1.204:8801 + apollo-config-service: http://192.168.1.204:8080 + namespace: application + apollo-access-key-secret: + cluster: seata + registry: + # support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa + type: eureka + preferred-networks: 30.240.* + eureka: + service-url: http://localhost:8761/eureka + application: default + weight: 1 + store: + # support: file 、 db 、 redis + mode: db + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druid + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true + user: mysql + password: mysql + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 + redis: + mode: single + database: 0 + min-conn: 1 + max-conn: 10 + password: + max-total: 100 + query-limit: 100 + single: + host: 127.0.0.1 + port: 6379 + sentinel: + master-name: + sentinel-hosts: + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login diff --git a/seata-server-deploy/ha/ha-erueka/src/main/resources/db/mysql.sql b/seata-server-deploy/ha/ha-erueka/src/main/resources/db/mysql.sql new file mode 100644 index 000000000..d401e1345 --- /dev/null +++ b/seata-server-deploy/ha/ha-erueka/src/main/resources/db/mysql.sql @@ -0,0 +1,73 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS `global_table` +( + `xid` VARCHAR(128) NOT NULL, + `transaction_id` BIGINT, + `status` TINYINT NOT NULL, + `application_id` VARCHAR(32), + `transaction_service_group` VARCHAR(32), + `transaction_name` VARCHAR(128), + `timeout` INT, + `begin_time` BIGINT, + `application_data` VARCHAR(2000), + `gmt_create` DATETIME, + `gmt_modified` DATETIME, + PRIMARY KEY (`xid`), + KEY `idx_status_gmt_modified` (`status` , `gmt_modified`), + KEY `idx_transaction_id` (`transaction_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS `branch_table` +( + `branch_id` BIGINT NOT NULL, + `xid` VARCHAR(128) NOT NULL, + `transaction_id` BIGINT, + `resource_group_id` VARCHAR(32), + `resource_id` VARCHAR(256), + `branch_type` VARCHAR(8), + `status` TINYINT, + `client_id` VARCHAR(64), + `application_data` VARCHAR(2000), + `gmt_create` DATETIME(6), + `gmt_modified` DATETIME(6), + PRIMARY KEY (`branch_id`), + KEY `idx_xid` (`xid`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS `lock_table` +( + `row_key` VARCHAR(128) NOT NULL, + `xid` VARCHAR(128), + `transaction_id` BIGINT, + `branch_id` BIGINT NOT NULL, + `resource_id` VARCHAR(256), + `table_name` VARCHAR(32), + `pk` VARCHAR(36), + `status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking', + `gmt_create` DATETIME, + `gmt_modified` DATETIME, + PRIMARY KEY (`row_key`), + KEY `idx_status` (`status`), + KEY `idx_branch_id` (`branch_id`), + KEY `idx_xid_and_branch_id` (`xid` , `branch_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +CREATE TABLE IF NOT EXISTS `distributed_lock` +( + `lock_key` CHAR(20) NOT NULL, + `lock_value` VARCHAR(20) NOT NULL, + `expire` BIGINT, + primary key (`lock_key`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-erueka/src/main/resources/db/oracle.sql b/seata-server-deploy/ha/ha-erueka/src/main/resources/db/oracle.sql new file mode 100644 index 000000000..437019a4d --- /dev/null +++ b/seata-server-deploy/ha/ha-erueka/src/main/resources/db/oracle.sql @@ -0,0 +1,72 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE global_table +( + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + status NUMBER(3) NOT NULL, + application_id VARCHAR2(32), + transaction_service_group VARCHAR2(32), + transaction_name VARCHAR2(128), + timeout NUMBER(10), + begin_time NUMBER(19), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE branch_table +( + branch_id NUMBER(19) NOT NULL, + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + resource_group_id VARCHAR2(32), + resource_id VARCHAR2(256), + branch_type VARCHAR2(8), + status NUMBER(3), + client_id VARCHAR2(64), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON branch_table (xid); + +-- the table to store lock data +CREATE TABLE lock_table +( + row_key VARCHAR2(128) NOT NULL, + xid VARCHAR2(128), + transaction_id NUMBER(19), + branch_id NUMBER(19) NOT NULL, + resource_id VARCHAR2(256), + table_name VARCHAR2(32), + pk VARCHAR2(36), + status NUMBER(3) NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (row_key) +); + +comment on column lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON lock_table (branch_id); +CREATE INDEX idx_xid_and_branch_id ON lock_table (xid, branch_id); +CREATE INDEX idx_status ON lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR2(20) NOT NULL, + lock_value VARCHAR2(20) NOT NULL, + expire DECIMAL(18) NOT NULL, + PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); diff --git a/seata-server-deploy/ha/ha-erueka/src/main/resources/db/postgresql.sql b/seata-server-deploy/ha/ha-erueka/src/main/resources/db/postgresql.sql new file mode 100644 index 000000000..f4727ef45 --- /dev/null +++ b/seata-server-deploy/ha/ha-erueka/src/main/resources/db/postgresql.sql @@ -0,0 +1,72 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS public.global_table +( + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + status SMALLINT NOT NULL, + application_id VARCHAR(32), + transaction_service_group VARCHAR(32), + transaction_name VARCHAR(128), + timeout INT, + begin_time BIGINT, + application_data VARCHAR(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_global_table PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON public.global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON public.global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS public.branch_table +( + branch_id BIGINT NOT NULL, + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + resource_group_id VARCHAR(32), + resource_id VARCHAR(256), + branch_type VARCHAR(8), + status SMALLINT, + client_id VARCHAR(64), + application_data VARCHAR(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + CONSTRAINT pk_branch_table PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON public.branch_table (xid); + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS public.lock_table +( + row_key VARCHAR(128) NOT NULL, + xid VARCHAR(128), + transaction_id BIGINT, + branch_id BIGINT NOT NULL, + resource_id VARCHAR(256), + table_name VARCHAR(32), + pk VARCHAR(36), + status SMALLINT NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_lock_table PRIMARY KEY (row_key) +); + +comment on column public.lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON public.lock_table (branch_id); +CREATE INDEX idx_xid_and_branch_id ON public.lock_table (xid, branch_id); +CREATE INDEX idx_status ON public.lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR(20) NOT NULL, + lock_value VARCHAR(20) NOT NULL, + expire BIGINT NOT NULL, + CONSTRAINT pk_distributed_lock_table PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); diff --git a/seata-server-deploy/ha/ha-nacos/pom.xml b/seata-server-deploy/ha/ha-nacos/pom.xml new file mode 100644 index 000000000..79150220a --- /dev/null +++ b/seata-server-deploy/ha/ha-nacos/pom.xml @@ -0,0 +1,19 @@ + + + + ha + io.seata + 1.1.0 + + 4.0.0 + + ha-nacos + + + 8 + 8 + + + \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-nacos/src/main/resources/application.yml b/seata-server-deploy/ha/ha-nacos/src/main/resources/application.yml new file mode 100644 index 000000000..37e66454b --- /dev/null +++ b/seata-server-deploy/ha/ha-nacos/src/main/resources/application.yml @@ -0,0 +1,102 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos 、 consul 、 apollo 、 zk 、 etcd3 + type: nacos + nacos: + server-addr: 127.0.0.1:8848 + namespace: + group: SEATA_GROUP + username: + password: + ##if use MSE Nacos with auth, mutex with username/password attribute + #access-key: "" + #secret-key: "" + data-id: seataServer.properties + registry: + # support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa + type: nacos + preferred-networks: 30.240.* + nacos: + application: seata-server + server-addr: 127.0.0.1:8848 + group: SEATA_GROUP + namespace: + cluster: default + username: + password: + ##if use MSE Nacos with auth, mutex with username/password attribute + #access-key: "" + #secret-key: "" + store: + # support: file 、 db 、 redis + mode: db + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druid + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true + user: mysql + password: mysql + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 + redis: + mode: single + database: 0 + min-conn: 1 + max-conn: 10 + password: + max-total: 100 + query-limit: 100 + single: + host: 127.0.0.1 + port: 6379 + sentinel: + master-name: + sentinel-hosts: + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login diff --git a/seata-server-deploy/ha/ha-nacos/src/main/resources/db/mysql.sql b/seata-server-deploy/ha/ha-nacos/src/main/resources/db/mysql.sql new file mode 100644 index 000000000..d401e1345 --- /dev/null +++ b/seata-server-deploy/ha/ha-nacos/src/main/resources/db/mysql.sql @@ -0,0 +1,73 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS `global_table` +( + `xid` VARCHAR(128) NOT NULL, + `transaction_id` BIGINT, + `status` TINYINT NOT NULL, + `application_id` VARCHAR(32), + `transaction_service_group` VARCHAR(32), + `transaction_name` VARCHAR(128), + `timeout` INT, + `begin_time` BIGINT, + `application_data` VARCHAR(2000), + `gmt_create` DATETIME, + `gmt_modified` DATETIME, + PRIMARY KEY (`xid`), + KEY `idx_status_gmt_modified` (`status` , `gmt_modified`), + KEY `idx_transaction_id` (`transaction_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS `branch_table` +( + `branch_id` BIGINT NOT NULL, + `xid` VARCHAR(128) NOT NULL, + `transaction_id` BIGINT, + `resource_group_id` VARCHAR(32), + `resource_id` VARCHAR(256), + `branch_type` VARCHAR(8), + `status` TINYINT, + `client_id` VARCHAR(64), + `application_data` VARCHAR(2000), + `gmt_create` DATETIME(6), + `gmt_modified` DATETIME(6), + PRIMARY KEY (`branch_id`), + KEY `idx_xid` (`xid`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS `lock_table` +( + `row_key` VARCHAR(128) NOT NULL, + `xid` VARCHAR(128), + `transaction_id` BIGINT, + `branch_id` BIGINT NOT NULL, + `resource_id` VARCHAR(256), + `table_name` VARCHAR(32), + `pk` VARCHAR(36), + `status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking', + `gmt_create` DATETIME, + `gmt_modified` DATETIME, + PRIMARY KEY (`row_key`), + KEY `idx_status` (`status`), + KEY `idx_branch_id` (`branch_id`), + KEY `idx_xid_and_branch_id` (`xid` , `branch_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +CREATE TABLE IF NOT EXISTS `distributed_lock` +( + `lock_key` CHAR(20) NOT NULL, + `lock_value` VARCHAR(20) NOT NULL, + `expire` BIGINT, + primary key (`lock_key`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-nacos/src/main/resources/db/oracle.sql b/seata-server-deploy/ha/ha-nacos/src/main/resources/db/oracle.sql new file mode 100644 index 000000000..437019a4d --- /dev/null +++ b/seata-server-deploy/ha/ha-nacos/src/main/resources/db/oracle.sql @@ -0,0 +1,72 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE global_table +( + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + status NUMBER(3) NOT NULL, + application_id VARCHAR2(32), + transaction_service_group VARCHAR2(32), + transaction_name VARCHAR2(128), + timeout NUMBER(10), + begin_time NUMBER(19), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE branch_table +( + branch_id NUMBER(19) NOT NULL, + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + resource_group_id VARCHAR2(32), + resource_id VARCHAR2(256), + branch_type VARCHAR2(8), + status NUMBER(3), + client_id VARCHAR2(64), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON branch_table (xid); + +-- the table to store lock data +CREATE TABLE lock_table +( + row_key VARCHAR2(128) NOT NULL, + xid VARCHAR2(128), + transaction_id NUMBER(19), + branch_id NUMBER(19) NOT NULL, + resource_id VARCHAR2(256), + table_name VARCHAR2(32), + pk VARCHAR2(36), + status NUMBER(3) NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (row_key) +); + +comment on column lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON lock_table (branch_id); +CREATE INDEX idx_xid_and_branch_id ON lock_table (xid, branch_id); +CREATE INDEX idx_status ON lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR2(20) NOT NULL, + lock_value VARCHAR2(20) NOT NULL, + expire DECIMAL(18) NOT NULL, + PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); diff --git a/seata-server-deploy/ha/ha-nacos/src/main/resources/db/postgresql.sql b/seata-server-deploy/ha/ha-nacos/src/main/resources/db/postgresql.sql new file mode 100644 index 000000000..f4727ef45 --- /dev/null +++ b/seata-server-deploy/ha/ha-nacos/src/main/resources/db/postgresql.sql @@ -0,0 +1,72 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS public.global_table +( + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + status SMALLINT NOT NULL, + application_id VARCHAR(32), + transaction_service_group VARCHAR(32), + transaction_name VARCHAR(128), + timeout INT, + begin_time BIGINT, + application_data VARCHAR(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_global_table PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON public.global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON public.global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS public.branch_table +( + branch_id BIGINT NOT NULL, + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + resource_group_id VARCHAR(32), + resource_id VARCHAR(256), + branch_type VARCHAR(8), + status SMALLINT, + client_id VARCHAR(64), + application_data VARCHAR(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + CONSTRAINT pk_branch_table PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON public.branch_table (xid); + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS public.lock_table +( + row_key VARCHAR(128) NOT NULL, + xid VARCHAR(128), + transaction_id BIGINT, + branch_id BIGINT NOT NULL, + resource_id VARCHAR(256), + table_name VARCHAR(32), + pk VARCHAR(36), + status SMALLINT NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_lock_table PRIMARY KEY (row_key) +); + +comment on column public.lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON public.lock_table (branch_id); +CREATE INDEX idx_xid_and_branch_id ON public.lock_table (xid, branch_id); +CREATE INDEX idx_status ON public.lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR(20) NOT NULL, + lock_value VARCHAR(20) NOT NULL, + expire BIGINT NOT NULL, + CONSTRAINT pk_distributed_lock_table PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); diff --git a/seata-server-deploy/ha/ha-zookeeper/pom.xml b/seata-server-deploy/ha/ha-zookeeper/pom.xml new file mode 100644 index 000000000..28178bfd3 --- /dev/null +++ b/seata-server-deploy/ha/ha-zookeeper/pom.xml @@ -0,0 +1,19 @@ + + + + ha + io.seata + 1.1.0 + + 4.0.0 + + ha-zookeeper + + + 8 + 8 + + + \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-zookeeper/src/main/resources/application.yml b/seata-server-deploy/ha/ha-zookeeper/src/main/resources/application.yml new file mode 100644 index 000000000..decb28e6d --- /dev/null +++ b/seata-server-deploy/ha/ha-zookeeper/src/main/resources/application.yml @@ -0,0 +1,95 @@ +server: + port: 7091 + +spring: + application: + name: seata-server + +logging: + config: classpath:logback-spring.xml + file: + path: ${user.home}/logs/seata + extend: + logstash-appender: + destination: 127.0.0.1:4560 + kafka-appender: + bootstrap-servers: 127.0.0.1:9092 + topic: logback_to_logstash + +console: + user: + username: seata + password: seata + +seata: + config: + # support: nacos 、 consul 、 apollo 、 zk 、 etcd3 + type: zk + zk: + server-addr: 127.0.0.1:2181 + session-timeout: 6000 + connect-timeout: 2000 + username: + password: + node-path: /seata/seata.properties + registry: + # support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa + type: zk + preferred-networks: 30.240.* + zk: + cluster: default + server-addr: 127.0.0.1:2181 + session-timeout: 6000 + connect-timeout: 2000 + username: "" + password: "" + store: + # support: file 、 db 、 redis + mode: db + session: + mode: file + lock: + mode: file + file: + dir: sessionStore + max-branch-session-size: 16384 + max-global-session-size: 512 + file-write-buffer-cache-size: 16384 + session-reload-read-size: 100 + flush-disk-mode: async + db: + datasource: druid + db-type: mysql + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true + user: mysql + password: mysql + min-conn: 5 + max-conn: 100 + global-table: global_table + branch-table: branch_table + lock-table: lock_table + distributed-lock-table: distributed_lock + query-limit: 100 + max-wait: 5000 + redis: + mode: single + database: 0 + min-conn: 1 + max-conn: 10 + password: + max-total: 100 + query-limit: 100 + single: + host: 127.0.0.1 + port: 6379 + sentinel: + master-name: + sentinel-hosts: + # server: + # service-port: 8091 #If not configured, the default is '${server.port} + 1000' + security: + secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 + tokenValidityInMilliseconds: 1800000 + ignore: + urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login diff --git a/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/mysql.sql b/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/mysql.sql new file mode 100644 index 000000000..d401e1345 --- /dev/null +++ b/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/mysql.sql @@ -0,0 +1,73 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS `global_table` +( + `xid` VARCHAR(128) NOT NULL, + `transaction_id` BIGINT, + `status` TINYINT NOT NULL, + `application_id` VARCHAR(32), + `transaction_service_group` VARCHAR(32), + `transaction_name` VARCHAR(128), + `timeout` INT, + `begin_time` BIGINT, + `application_data` VARCHAR(2000), + `gmt_create` DATETIME, + `gmt_modified` DATETIME, + PRIMARY KEY (`xid`), + KEY `idx_status_gmt_modified` (`status` , `gmt_modified`), + KEY `idx_transaction_id` (`transaction_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS `branch_table` +( + `branch_id` BIGINT NOT NULL, + `xid` VARCHAR(128) NOT NULL, + `transaction_id` BIGINT, + `resource_group_id` VARCHAR(32), + `resource_id` VARCHAR(256), + `branch_type` VARCHAR(8), + `status` TINYINT, + `client_id` VARCHAR(64), + `application_data` VARCHAR(2000), + `gmt_create` DATETIME(6), + `gmt_modified` DATETIME(6), + PRIMARY KEY (`branch_id`), + KEY `idx_xid` (`xid`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS `lock_table` +( + `row_key` VARCHAR(128) NOT NULL, + `xid` VARCHAR(128), + `transaction_id` BIGINT, + `branch_id` BIGINT NOT NULL, + `resource_id` VARCHAR(256), + `table_name` VARCHAR(32), + `pk` VARCHAR(36), + `status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking', + `gmt_create` DATETIME, + `gmt_modified` DATETIME, + PRIMARY KEY (`row_key`), + KEY `idx_status` (`status`), + KEY `idx_branch_id` (`branch_id`), + KEY `idx_xid_and_branch_id` (`xid` , `branch_id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +CREATE TABLE IF NOT EXISTS `distributed_lock` +( + `lock_key` CHAR(20) NOT NULL, + `lock_value` VARCHAR(20) NOT NULL, + `expire` BIGINT, + primary key (`lock_key`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4; + +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); \ No newline at end of file diff --git a/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/oracle.sql b/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/oracle.sql new file mode 100644 index 000000000..437019a4d --- /dev/null +++ b/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/oracle.sql @@ -0,0 +1,72 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE global_table +( + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + status NUMBER(3) NOT NULL, + application_id VARCHAR2(32), + transaction_service_group VARCHAR2(32), + transaction_name VARCHAR2(128), + timeout NUMBER(10), + begin_time NUMBER(19), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE branch_table +( + branch_id NUMBER(19) NOT NULL, + xid VARCHAR2(128) NOT NULL, + transaction_id NUMBER(19), + resource_group_id VARCHAR2(32), + resource_id VARCHAR2(256), + branch_type VARCHAR2(8), + status NUMBER(3), + client_id VARCHAR2(64), + application_data VARCHAR2(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON branch_table (xid); + +-- the table to store lock data +CREATE TABLE lock_table +( + row_key VARCHAR2(128) NOT NULL, + xid VARCHAR2(128), + transaction_id NUMBER(19), + branch_id NUMBER(19) NOT NULL, + resource_id VARCHAR2(256), + table_name VARCHAR2(32), + pk VARCHAR2(36), + status NUMBER(3) NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + PRIMARY KEY (row_key) +); + +comment on column lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON lock_table (branch_id); +CREATE INDEX idx_xid_and_branch_id ON lock_table (xid, branch_id); +CREATE INDEX idx_status ON lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR2(20) NOT NULL, + lock_value VARCHAR2(20) NOT NULL, + expire DECIMAL(18) NOT NULL, + PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); diff --git a/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/postgresql.sql b/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/postgresql.sql new file mode 100644 index 000000000..f4727ef45 --- /dev/null +++ b/seata-server-deploy/ha/ha-zookeeper/src/main/resources/db/postgresql.sql @@ -0,0 +1,72 @@ +-- -------------------------------- The script used when storeMode is 'db' -------------------------------- +-- the table to store GlobalSession data +CREATE TABLE IF NOT EXISTS public.global_table +( + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + status SMALLINT NOT NULL, + application_id VARCHAR(32), + transaction_service_group VARCHAR(32), + transaction_name VARCHAR(128), + timeout INT, + begin_time BIGINT, + application_data VARCHAR(2000), + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_global_table PRIMARY KEY (xid) +); + +CREATE INDEX idx_status_gmt_modified ON public.global_table (status, gmt_modified); +CREATE INDEX idx_transaction_id ON public.global_table (transaction_id); + +-- the table to store BranchSession data +CREATE TABLE IF NOT EXISTS public.branch_table +( + branch_id BIGINT NOT NULL, + xid VARCHAR(128) NOT NULL, + transaction_id BIGINT, + resource_group_id VARCHAR(32), + resource_id VARCHAR(256), + branch_type VARCHAR(8), + status SMALLINT, + client_id VARCHAR(64), + application_data VARCHAR(2000), + gmt_create TIMESTAMP(6), + gmt_modified TIMESTAMP(6), + CONSTRAINT pk_branch_table PRIMARY KEY (branch_id) +); + +CREATE INDEX idx_xid ON public.branch_table (xid); + +-- the table to store lock data +CREATE TABLE IF NOT EXISTS public.lock_table +( + row_key VARCHAR(128) NOT NULL, + xid VARCHAR(128), + transaction_id BIGINT, + branch_id BIGINT NOT NULL, + resource_id VARCHAR(256), + table_name VARCHAR(32), + pk VARCHAR(36), + status SMALLINT NOT NULL DEFAULT 0, + gmt_create TIMESTAMP(0), + gmt_modified TIMESTAMP(0), + CONSTRAINT pk_lock_table PRIMARY KEY (row_key) +); + +comment on column public.lock_table.status is '0:locked ,1:rollbacking'; +CREATE INDEX idx_branch_id ON public.lock_table (branch_id); +CREATE INDEX idx_xid_and_branch_id ON public.lock_table (xid, branch_id); +CREATE INDEX idx_status ON public.lock_table (status); + +CREATE TABLE distributed_lock ( + lock_key VARCHAR(20) NOT NULL, + lock_value VARCHAR(20) NOT NULL, + expire BIGINT NOT NULL, + CONSTRAINT pk_distributed_lock_table PRIMARY KEY (lock_key) +); + +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); +INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); diff --git a/seata-server-deploy/ha/pom.xml b/seata-server-deploy/ha/pom.xml new file mode 100644 index 000000000..cd3fa2552 --- /dev/null +++ b/seata-server-deploy/ha/pom.xml @@ -0,0 +1,26 @@ + + + + seata-server-deploy + io.seata + 1.1.0 + + 4.0.0 + + ha + pom + + ha-nacos + ha-consul + ha-erueka + ha-zookeeper + + + + 8 + 8 + + + \ No newline at end of file diff --git a/seata-server-deploy/pom.xml b/seata-server-deploy/pom.xml new file mode 100644 index 000000000..571b30315 --- /dev/null +++ b/seata-server-deploy/pom.xml @@ -0,0 +1,24 @@ + + + + seata-samples + io.seata + 1.1.0 + + 4.0.0 + + seata-server-deploy + pom + + ha + file-depoly + + + + 8 + 8 + + + \ No newline at end of file diff --git a/sessionStore/root.data b/sessionStore/root.data new file mode 100644 index 000000000..f8de80fb4 Binary files /dev/null and b/sessionStore/root.data differ diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/pom.xml b/springcloud-eureka-feign-mybatis-seata/account-server/pom.xml deleted file mode 100644 index 597b3eaec..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - 4.0.0 - - io.seata.sample - springcloud-eureka-feign-mybatis-seata - 0.0.1-SNAPSHOT - - - io.seata.sample - account-server - 0.0.1-SNAPSHOT - account-server - Demo project for Spring Boot - - - 1.8 - Greenwich.SR2 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/AccountServerApplication.java b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/AccountServerApplication.java deleted file mode 100644 index 14e4fca13..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/AccountServerApplication.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.openfeign.EnableFeignClients; - -/** - * 账户服务 - * - * @author wangzhongxiang - */ -@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) -@MapperScan("io.seata.sample.dao") -@EnableDiscoveryClient -@EnableFeignClients -public class AccountServerApplication { - - public static void main(String[] args) { - SpringApplication.run(AccountServerApplication.class, args); - } - -} diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/DataSourceConfiguration.java b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/DataSourceConfiguration.java deleted file mode 100644 index d481a9e85..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/DataSourceConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample; - -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; - -import javax.sql.DataSource; - -import org.apache.ibatis.session.SqlSessionFactory; -import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.transaction.SpringManagedTransactionFactory; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; - -/** - * 数据源代理 - * - * @author wangzhongxiang - */ -@Configuration -public class DataSourceConfiguration { - - @Bean - @ConfigurationProperties(prefix = "spring.datasource") - public DataSource druidDataSource() { - DruidDataSource druidDataSource = new DruidDataSource(); - return druidDataSource; - } - - @Primary - @Bean("dataSource") - public DataSourceProxy dataSource(DataSource druidDataSource) { - return new DataSourceProxy(druidDataSource); - } - - @Bean - public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception { - SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); - sqlSessionFactoryBean.setDataSource(dataSourceProxy); - sqlSessionFactoryBean.setMapperLocations( - new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/*.xml")); - sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory()); - return sqlSessionFactoryBean.getObject(); - } - -} diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/controller/AccountController.java b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/controller/AccountController.java deleted file mode 100644 index 3a1598d20..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/controller/AccountController.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.controller; - -import io.seata.sample.service.AccountService; - -import java.math.BigDecimal; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author IT云清 - */ -@RestController -@RequestMapping("account") -public class AccountController { - - @Autowired - private AccountService accountServiceImpl; - - /** - * 扣减账户余额 - * - * @param userId 用户id - * @param money 金额 - * @return - */ - @RequestMapping("decrease") - public String decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money) { - accountServiceImpl.decrease(userId, money); - return "Account decrease success"; - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/dao/AccountDao.java b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/dao/AccountDao.java deleted file mode 100644 index fbb880903..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/dao/AccountDao.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.dao; - -import java.math.BigDecimal; - -import org.apache.ibatis.annotations.Param; - -/** - * @author IT云清 - */ -public interface AccountDao { - - /** - * 扣减账户余额 - * - * @param userId 用户id - * @param money 金额 - */ - void decrease(@Param("userId") Long userId, @Param("money") BigDecimal money); -} diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/entity/Account.java b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/entity/Account.java deleted file mode 100644 index 16d2bc923..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/entity/Account.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.entity; - -import java.math.BigDecimal; - -import lombok.Data; - -/** - * @author IT云清 - */ -@Data -public class Account { - - private Long id; - - /** - * 用户id - */ - private Long userId; - - /** - * 总额度 - */ - private BigDecimal total; - - /** - * 已用额度 - */ - private BigDecimal used; - - /** - * 剩余额度 - */ - private BigDecimal residue; -} diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/service/AccountService.java b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/service/AccountService.java deleted file mode 100644 index 501ce4ebe..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/service/AccountService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.service; - -import java.math.BigDecimal; - -/** - * @author IT云清 - */ -public interface AccountService { - - /** - * 扣减账户余额 - * - * @param userId 用户id - * @param money 金额 - */ - void decrease(Long userId, BigDecimal money); -} diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/service/AccountServiceImpl.java b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/service/AccountServiceImpl.java deleted file mode 100644 index 018b3b358..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/java/io/seata/sample/service/AccountServiceImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.service; - -import io.seata.sample.dao.AccountDao; -import io.seata.sample.feign.OrderApi; - -import java.math.BigDecimal; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * @author IT云清 - */ -@Service("accountServiceImpl") -public class AccountServiceImpl implements AccountService { - - private static final Logger LOGGER = LoggerFactory.getLogger(AccountServiceImpl.class); - @Autowired - private AccountDao accountDao; - @Autowired - private OrderApi orderApi; - - /** - * 扣减账户余额 - * - * @param userId 用户id - * @param money 金额 - */ - @Override - public void decrease(Long userId, BigDecimal money) { - LOGGER.info("------->扣减账户开始account中"); - //模拟超时异常,全局事务回滚 - // try { - // Thread.sleep(30*1000); - // } catch (InterruptedException e) { - // e.printStackTrace(); - // } - accountDao.decrease(userId, money); - LOGGER.info("------->扣减账户结束account中"); - - //修改订单状态,此调用会导致调用成环 - LOGGER.info("修改订单状态开始"); - String mes = orderApi.update(userId, money.multiply(new BigDecimal("0.09")), 0); - LOGGER.info("修改订单状态结束:{}", mes); - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/account.sql b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/account.sql deleted file mode 100644 index 17f54e6ef..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/account.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE `account` -( - `id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT 'id', - `user_id` bigint(11) DEFAULT NULL COMMENT '用户id', - `total` decimal(10, 0) DEFAULT NULL COMMENT '总额度', - `used` decimal(10, 0) DEFAULT NULL COMMENT '已用余额', - `residue` decimal(10, 0) DEFAULT '0' COMMENT '剩余可用额度', - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; - -INSERT INTO `account` (`id`, `user_id`, `total`, `used`, `residue`) -VALUES ('1', '1', '1000', '0', '100'); diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/application.yml b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/application.yml deleted file mode 100644 index 10b519228..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/application.yml +++ /dev/null @@ -1,34 +0,0 @@ -eureka: - instance: - hostname: localhost - prefer-ip-address: true - client: - serviceUrl: - defaultZone: http://${eureka.instance.hostname}:8761/eureka/ -feign: - client: - config: - default: - connectTimeout: 5000 - readTimeout: 10000 -logging: - level: - io: - seata: info -mybatis: - mapperLocations: classpath:mapper/*.xml - typeAliasesPackage: io.seata.sample.entity -server: - port: 8181 -spring: - application: - name: account-server - cloud: - alibaba: - seata: - tx-service-group: my_test_tx_group - datasource: - driver-class-name: com.mysql.jdbc.Driver - password: 123456 - url: jdbc:mysql://127.0.0.1:3306/seata - username: root diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/file.conf b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/file.conf deleted file mode 100644 index e38ee8290..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/file.conf +++ /dev/null @@ -1,66 +0,0 @@ -transport { - # tcp udt unix-domain-socket - type = "TCP" - #NIO NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the client batch send request enable - enableClientBatchSendRequest = true - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size,will not be used for UDT - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "127.0.0.1:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - reportSuccessEnable = false - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - } - undo { - dataValidation = true - logSerialization = "jackson" - logTable = "undo_log" - } - log { - exceptionRate = 100 - } -} \ No newline at end of file diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/mapper/AccountMapper.xml b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/mapper/AccountMapper.xml deleted file mode 100644 index c1cfaecf2..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/mapper/AccountMapper.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - UPDATE account - SET residue = residue - #{money}, - used = used + #{money} - where user_id = #{userId}; - - diff --git a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/registry.conf b/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/registry.conf deleted file mode 100644 index 66a4206ce..000000000 --- a/springcloud-eureka-feign-mybatis-seata/account-server/src/main/resources/registry.conf +++ /dev/null @@ -1,82 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "eureka" - - nacos { - serverAddr = "localhost" - namespace = "" - cluster = "default" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - application = "default" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - password = "" - cluster = "default" - timeout = "0" - } - zk { - cluster = "default" - serverAddr = "127.0.0.1:2181" - session.timeout = 6000 - connect.timeout = 2000 - username = "" - password = "" - } - consul { - cluster = "default" - serverAddr = "127.0.0.1:8500" - } - etcd3 { - cluster = "default" - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - application = "default" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - cluster = "default" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig - type = "file" - - nacos { - serverAddr = "localhost" - namespace = "" - group = "SEATA_GROUP" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - app.id = "seata-server" - apollo.meta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - session.timeout = 6000 - connect.timeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/eureka-server/pom.xml b/springcloud-eureka-feign-mybatis-seata/eureka-server/pom.xml deleted file mode 100644 index f2cba715c..000000000 --- a/springcloud-eureka-feign-mybatis-seata/eureka-server/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.8.RELEASE - - - io.seata.sample - eureka-server - 0.0.1-SNAPSHOT - eureka-server - Demo project for Spring Boot - - - 1.8 - Greenwich.SR2 - - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-server - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - diff --git a/springcloud-eureka-feign-mybatis-seata/eureka-server/src/main/java/io/seata/sample/EurekaServerApplication.java b/springcloud-eureka-feign-mybatis-seata/eureka-server/src/main/java/io/seata/sample/EurekaServerApplication.java deleted file mode 100644 index 8ea60b237..000000000 --- a/springcloud-eureka-feign-mybatis-seata/eureka-server/src/main/java/io/seata/sample/EurekaServerApplication.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; - -/** - * @author wangzhongxiang - */ -@EnableEurekaServer -@SpringBootApplication -public class EurekaServerApplication { - - public static void main(String[] args) { - SpringApplication.run(EurekaServerApplication.class, args); - } - -} diff --git a/springcloud-eureka-feign-mybatis-seata/eureka-server/src/main/resources/application.yml b/springcloud-eureka-feign-mybatis-seata/eureka-server/src/main/resources/application.yml deleted file mode 100644 index d6b413479..000000000 --- a/springcloud-eureka-feign-mybatis-seata/eureka-server/src/main/resources/application.yml +++ /dev/null @@ -1,14 +0,0 @@ -server: - port: 8761 -spring: - application: - name: eureka-server -eureka: - instance: - hostname: localhost - client: - register-with-eureka: false - fetch-registry: false - service-url: - defultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ - diff --git a/springcloud-eureka-feign-mybatis-seata/eureka-server/src/test/java/io/seata/sample/EurekaServerApplicationTests.java b/springcloud-eureka-feign-mybatis-seata/eureka-server/src/test/java/io/seata/sample/EurekaServerApplicationTests.java deleted file mode 100644 index b726de6ac..000000000 --- a/springcloud-eureka-feign-mybatis-seata/eureka-server/src/test/java/io/seata/sample/EurekaServerApplicationTests.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class EurekaServerApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/pom.xml b/springcloud-eureka-feign-mybatis-seata/order-server/pom.xml deleted file mode 100644 index 617004f6b..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - 4.0.0 - - io.seata.sample - springcloud-eureka-feign-mybatis-seata - 0.0.1-SNAPSHOT - - - io.seata.sample - order-server - 0.0.1-SNAPSHOT - order-server - Demo project for Spring Boot - - - - 1.8 - Greenwich.SR2 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/DataSourceConfiguration.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/DataSourceConfiguration.java deleted file mode 100644 index d481a9e85..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/DataSourceConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample; - -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; - -import javax.sql.DataSource; - -import org.apache.ibatis.session.SqlSessionFactory; -import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.transaction.SpringManagedTransactionFactory; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; - -/** - * 数据源代理 - * - * @author wangzhongxiang - */ -@Configuration -public class DataSourceConfiguration { - - @Bean - @ConfigurationProperties(prefix = "spring.datasource") - public DataSource druidDataSource() { - DruidDataSource druidDataSource = new DruidDataSource(); - return druidDataSource; - } - - @Primary - @Bean("dataSource") - public DataSourceProxy dataSource(DataSource druidDataSource) { - return new DataSourceProxy(druidDataSource); - } - - @Bean - public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception { - SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); - sqlSessionFactoryBean.setDataSource(dataSourceProxy); - sqlSessionFactoryBean.setMapperLocations( - new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/*.xml")); - sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory()); - return sqlSessionFactoryBean.getObject(); - } - -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/OrderServerApplication.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/OrderServerApplication.java deleted file mode 100644 index d631a3361..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/OrderServerApplication.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.openfeign.EnableFeignClients; - -/** - * 订单服务 - * - * @author wangzhongxiang - */ -@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) -@MapperScan("io.seata.sample.dao") -@EnableDiscoveryClient -@EnableFeignClients -public class OrderServerApplication { - - public static void main(String[] args) { - SpringApplication.run(OrderServerApplication.class, args); - } - -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/controller/OrderController.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/controller/OrderController.java deleted file mode 100644 index 1417ba12a..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/controller/OrderController.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.controller; - -import io.seata.sample.entity.Order; -import io.seata.sample.service.OrderService; - -import java.math.BigDecimal; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author IT云清 - */ -@RestController -@RequestMapping(value = "order") -public class OrderController { - - @Autowired - private OrderService orderServiceImpl; - - /** - * 创建订单 - * - * @param order - * @return - */ - @GetMapping("create") - public String create(Order order) { - orderServiceImpl.create(order); - return "Create order success"; - } - - /** - * 修改订单状态 - * - * @param userId - * @param money - * @param status - * @return - */ - @RequestMapping("update") - String update(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money, - @RequestParam("status") Integer status) { - orderServiceImpl.update(userId, money, status); - return "订单状态修改成功"; - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/dao/OrderDao.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/dao/OrderDao.java deleted file mode 100644 index 734c363ab..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/dao/OrderDao.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.dao; - -import io.seata.sample.entity.Order; - -import java.math.BigDecimal; - -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -/** - * @author IT云清 - */ -@Repository -public interface OrderDao { - - /** - * 创建订单 - * - * @param order - * @return - */ - void create(Order order); - - /** - * 修改订单金额 - * - * @param userId - * @param money - */ - void update(@Param("userId") Long userId, @Param("money") BigDecimal money, @Param("status") Integer status); -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/entity/Order.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/entity/Order.java deleted file mode 100644 index bedefbdf0..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/entity/Order.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.entity; - -import java.math.BigDecimal; - -import lombok.Data; - -/** - * 订单 - * - * @author IT云清 - */ -@Data -public class Order { - - private Long id; - - private Long userId; - - private Long productId; - - private Integer count; - - private BigDecimal money; - - /** - * 订单状态:0:创建中;1:已完结 - */ - private Integer status; - -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/feign/AccountApi.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/feign/AccountApi.java deleted file mode 100644 index 98b76bf44..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/feign/AccountApi.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.feign; - -import java.math.BigDecimal; - -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * @author IT云清 - */ -@FeignClient(value = "account-server") -public interface AccountApi { - - /** - * 扣减账户余额 - * - * @param userId 用户id - * @param money 金额 - * @return - */ - @RequestMapping("/account/decrease") - String decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money); -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/feign/StockApi.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/feign/StockApi.java deleted file mode 100644 index cd767e0d3..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/feign/StockApi.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.feign; - -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * @author IT云清 - */ -@FeignClient(value = "stock-server") -public interface StockApi { - - /** - * 扣减库存 - * - * @param productId - * @param count - * @return - */ - @GetMapping(value = "/stock/decrease") - String decrease(@RequestParam("productId") Long productId, @RequestParam("count") Integer count); -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/service/OrderService.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/service/OrderService.java deleted file mode 100644 index 06b5df208..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/service/OrderService.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.service; - -import io.seata.sample.entity.Order; - -import java.math.BigDecimal; - -/** - * @author IT云清 - */ -public interface OrderService { - - /** - * 创建订单 - * - * @param order - * @return - */ - void create(Order order); - - /** - * 修改订单状态 - * - * @param userId - * @param money - * @param status - */ - void update(Long userId, BigDecimal money, Integer status); -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/service/OrderServiceImpl.java b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/service/OrderServiceImpl.java deleted file mode 100644 index bd877b30e..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/java/io/seata/sample/service/OrderServiceImpl.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.service; - -import io.seata.sample.dao.OrderDao; -import io.seata.sample.entity.Order; -import io.seata.sample.feign.AccountApi; -import io.seata.sample.feign.StockApi; -import io.seata.spring.annotation.GlobalTransactional; - -import java.math.BigDecimal; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * @author IT云清 - */ -@Service("orderServiceImpl") -public class OrderServiceImpl implements OrderService { - - private static final Logger LOGGER = LoggerFactory.getLogger(OrderServiceImpl.class); - - @Autowired - private OrderDao orderDao; - @Autowired - private StockApi stockApi; - @Autowired - private AccountApi accountApi; - - /** - * 创建订单 - * - * @param order - * @return 测试结果: - * 1.添加本地事务:仅仅扣减库存 - * 2.不添加本地事务:创建订单,扣减库存 - */ - @Override - @GlobalTransactional(name = "fsp-create-order", rollbackFor = Exception.class) - public void create(Order order) { - LOGGER.info("------->交易开始"); - //本地方法 - orderDao.create(order); - - //远程方法 扣减库存 - stockApi.decrease(order.getProductId(), order.getCount()); - - //远程方法 扣减账户余额 - - LOGGER.info("------->扣减账户开始order中"); - accountApi.decrease(order.getUserId(), order.getMoney()); - LOGGER.info("------->扣减账户结束order中"); - - LOGGER.info("------->交易结束"); - } - - /** - * 修改订单状态 - */ - @Override - public void update(Long userId, BigDecimal money, Integer status) { - LOGGER.info("修改订单状态,入参为:userId={},money={},status={}", userId, money, status); - orderDao.update(userId, money, status); - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/application.yml b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/application.yml deleted file mode 100644 index 57735f5c8..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/application.yml +++ /dev/null @@ -1,36 +0,0 @@ -eureka: - instance: - hostname: localhost - prefer-ip-address: true - client: - serviceUrl: - defaultZone: http://${eureka.instance.hostname}:8761/eureka/ -feign: - hystrix: - enabled: false - client: - config: - default: - connectTimeout: 60000 - readTimeout: 60000 -logging: - level: - io: - seata: info -mybatis: - mapperLocations: classpath:mapper/*.xml - typeAliasesPackage: io.seata.sample.entity -server: - port: 8180 -spring: - application: - name: order-server - cloud: - alibaba: - seata: - tx-service-group: my_test_tx_group - datasource: - driver-class-name: com.mysql.jdbc.Driver - password: 123456 - url: jdbc:mysql://127.0.0.1:3306/seata - username: root diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/file.conf b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/file.conf deleted file mode 100644 index e38ee8290..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/file.conf +++ /dev/null @@ -1,66 +0,0 @@ -transport { - # tcp udt unix-domain-socket - type = "TCP" - #NIO NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the client batch send request enable - enableClientBatchSendRequest = true - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size,will not be used for UDT - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "127.0.0.1:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - reportSuccessEnable = false - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - } - undo { - dataValidation = true - logSerialization = "jackson" - logTable = "undo_log" - } - log { - exceptionRate = 100 - } -} \ No newline at end of file diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/mapper/OrderMapper.xml b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/mapper/OrderMapper.xml deleted file mode 100644 index f028f129f..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/mapper/OrderMapper.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - INSERT INTO `order` (`id`, `user_id`, `product_id`, `count`, `money`, `status`) - VALUES (NULL, #{userId}, #{productId}, #{count}, #{money}, 0); - - - - UPDATE `order` - SET money = money - #{money}, - status = 1 - where user_id = #{userId} - and status = #{status}; - - diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/order.sql b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/order.sql deleted file mode 100644 index 4109f8ba2..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/order.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE `order` -( - `id` bigint(11) NOT NULL AUTO_INCREMENT, - `user_id` bigint(11) DEFAULT NULL COMMENT '用户id', - `product_id` bigint(11) DEFAULT NULL COMMENT '产品id', - `count` int(11) DEFAULT NULL COMMENT '数量', - `money` decimal(11, 0) DEFAULT NULL COMMENT '金额', - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; - -ALTER TABLE `order` - ADD COLUMN `status` int(1) DEFAULT NULL COMMENT '订单状态:0:创建中;1:已完结' AFTER `money`; - - diff --git a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/registry.conf b/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/registry.conf deleted file mode 100644 index 66a4206ce..000000000 --- a/springcloud-eureka-feign-mybatis-seata/order-server/src/main/resources/registry.conf +++ /dev/null @@ -1,82 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "eureka" - - nacos { - serverAddr = "localhost" - namespace = "" - cluster = "default" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - application = "default" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - password = "" - cluster = "default" - timeout = "0" - } - zk { - cluster = "default" - serverAddr = "127.0.0.1:2181" - session.timeout = 6000 - connect.timeout = 2000 - username = "" - password = "" - } - consul { - cluster = "default" - serverAddr = "127.0.0.1:8500" - } - etcd3 { - cluster = "default" - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - application = "default" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - cluster = "default" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig - type = "file" - - nacos { - serverAddr = "localhost" - namespace = "" - group = "SEATA_GROUP" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - app.id = "seata-server" - apollo.meta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - session.timeout = 6000 - connect.timeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/pom.xml b/springcloud-eureka-feign-mybatis-seata/pom.xml deleted file mode 100644 index 0068abda9..000000000 --- a/springcloud-eureka-feign-mybatis-seata/pom.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - 4.0.0 - io.seata.sample - springcloud-eureka-feign-mybatis-seata - 0.0.1-SNAPSHOT - pom - - springcloud-eureka-feign-mybatis-seata - Demo project for Spring Boot - - - order-server - account-server - storage-server - - - - 1.8 - 8.0.24 - 2.0.0 - 1.1.10 - 1.18.8 - 1.4.2 - 2.1.8.RELEASE - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - ${mybatis-spring-boot-starter.version} - - - - mysql - mysql-connector-java - ${mysql-connector-java.version} - - - - com.alibaba - druid-spring-boot-starter - ${druid-spring-boot-starter.version} - - - - org.projectlombok - lombok - ${lombok.version} - - - - com.alibaba.cloud - spring-cloud-alibaba-seata - 2.1.0.RELEASE - - - seata-all - io.seata - - - - - io.seata - seata-all - ${seata.version} - - - - - - - - org.springframework.boot - spring-boot-dependencies - ${springboot.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/pom.xml b/springcloud-eureka-feign-mybatis-seata/storage-server/pom.xml deleted file mode 100644 index 45fb4a2a0..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - 4.0.0 - - io.seata.sample - springcloud-eureka-feign-mybatis-seata - 0.0.1-SNAPSHOT - - - io.seata.sample - stock-server - 0.0.1-SNAPSHOT - stock-server - Demo project for Spring Boot - - - 1.8 - Greenwich.SR2 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/DataSourceConfiguration.java b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/DataSourceConfiguration.java deleted file mode 100644 index d481a9e85..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/DataSourceConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample; - -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; - -import javax.sql.DataSource; - -import org.apache.ibatis.session.SqlSessionFactory; -import org.mybatis.spring.SqlSessionFactoryBean; -import org.mybatis.spring.transaction.SpringManagedTransactionFactory; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; - -/** - * 数据源代理 - * - * @author wangzhongxiang - */ -@Configuration -public class DataSourceConfiguration { - - @Bean - @ConfigurationProperties(prefix = "spring.datasource") - public DataSource druidDataSource() { - DruidDataSource druidDataSource = new DruidDataSource(); - return druidDataSource; - } - - @Primary - @Bean("dataSource") - public DataSourceProxy dataSource(DataSource druidDataSource) { - return new DataSourceProxy(druidDataSource); - } - - @Bean - public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy) throws Exception { - SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); - sqlSessionFactoryBean.setDataSource(dataSourceProxy); - sqlSessionFactoryBean.setMapperLocations( - new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/*.xml")); - sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory()); - return sqlSessionFactoryBean.getObject(); - } - -} diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/StockServerApplication.java b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/StockServerApplication.java deleted file mode 100644 index 422c0e74a..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/StockServerApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; - -/** - * 库存服务 - * - * @author wangzhongxiang - */ -@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) -@MapperScan("io.seata.sample.dao") -public class StockServerApplication { - - public static void main(String[] args) { - SpringApplication.run(StockServerApplication.class, args); - } - -} diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/controller/StockController.java b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/controller/StockController.java deleted file mode 100644 index 8bc82b1a3..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/controller/StockController.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.controller; - -import io.seata.sample.service.StockService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author IT云清 - */ -@RestController -@RequestMapping("stock") -public class StockController { - - @Autowired - private StockService stockServiceImpl; - - /** - * 扣减库存 - * - * @param productId 产品id - * @param count 数量 - * @return - */ - @RequestMapping("decrease") - public String decrease(@RequestParam("productId") Long productId, @RequestParam("count") Integer count) { - stockServiceImpl.decrease(productId, count); - return "Decrease stock success"; - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/dao/StockDao.java b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/dao/StockDao.java deleted file mode 100644 index 8c587d465..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/dao/StockDao.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.dao; - -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -/** - * @author IT云清 - */ -@Repository -public interface StockDao { - - /** - * 扣减库存 - * - * @param productId 产品id - * @param count 数量 - * @return - */ - void decrease(@Param("productId") Long productId, @Param("count") Integer count); -} diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/entity/Stock.java b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/entity/Stock.java deleted file mode 100644 index 70590055f..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/entity/Stock.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.entity; - -import lombok.Data; - -/** - * @author IT云清 - */ -@Data -public class Stock { - - private Long id; - - /** - * 产品id - */ - private Long productId; - - /** - * 总库存 - */ - private Integer total; - - /** - * 已用库存 - */ - private Integer used; - - /** - * 剩余库存 - */ - private Integer residue; -} diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/service/StockService.java b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/service/StockService.java deleted file mode 100644 index b9ca1cbab..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/service/StockService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.service; - -/** - * @author IT云清 - */ -public interface StockService { - - /** - * 扣减库存 - * - * @param productId 产品id - * @param count 数量 - * @return - */ - void decrease(Long productId, Integer count); -} diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/service/StockServiceImpl.java b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/service/StockServiceImpl.java deleted file mode 100644 index 6ee4aea8b..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/java/io/seata/sample/service/StockServiceImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.seata.sample.service; - -import io.seata.sample.dao.StockDao; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * @author IT云清 - */ -@Service("stockServiceImpl") -public class StockServiceImpl implements StockService { - - private static final Logger LOGGER = LoggerFactory.getLogger(StockServiceImpl.class); - - @Autowired - private StockDao stockDao; - - /** - * 扣减库存 - * - * @param productId 产品id - * @param count 数量 - * @return - */ - @Override - public void decrease(Long productId, Integer count) { - LOGGER.info("------->扣减库存开始"); - stockDao.decrease(productId, count); - LOGGER.info("------->扣减库存结束"); - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/application.yml b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/application.yml deleted file mode 100644 index 91c9a10d3..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/application.yml +++ /dev/null @@ -1,28 +0,0 @@ -eureka: - client: - serviceUrl: - defaultZone: http://${eureka.instance.hostname}:8761/eureka/ - instance: - hostname: localhost - prefer-ip-address: true -logging: - level: - io: - seata: info -mybatis: - mapperLocations: classpath:mapper/*.xml - typeAliasesPackage: io.seata.sample.entity -server: - port: 8182 -spring: - application: - name: stock-server - cloud: - alibaba: - seata: - tx-service-group: my_test_tx_group - datasource: - driver-class-name: com.mysql.jdbc.Driver - password: 123456 - url: jdbc:mysql://127.0.0.1:3306/seata - username: root diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/file.conf b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/file.conf deleted file mode 100644 index e38ee8290..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/file.conf +++ /dev/null @@ -1,66 +0,0 @@ -transport { - # tcp udt unix-domain-socket - type = "TCP" - #NIO NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the client batch send request enable - enableClientBatchSendRequest = true - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size,will not be used for UDT - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "127.0.0.1:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - reportSuccessEnable = false - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - } - undo { - dataValidation = true - logSerialization = "jackson" - logTable = "undo_log" - } - log { - exceptionRate = 100 - } -} \ No newline at end of file diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/mapper/StorageMapper.xml b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/mapper/StorageMapper.xml deleted file mode 100644 index 07faa3dea..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/mapper/StorageMapper.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - UPDATE stock - SET used = used + #{count}, - residue = residue - #{count} - WHERE product_id = #{productId} - - diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/registry.conf b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/registry.conf deleted file mode 100644 index 66a4206ce..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/registry.conf +++ /dev/null @@ -1,82 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "eureka" - - nacos { - serverAddr = "localhost" - namespace = "" - cluster = "default" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - application = "default" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - password = "" - cluster = "default" - timeout = "0" - } - zk { - cluster = "default" - serverAddr = "127.0.0.1:2181" - session.timeout = 6000 - connect.timeout = 2000 - username = "" - password = "" - } - consul { - cluster = "default" - serverAddr = "127.0.0.1:8500" - } - etcd3 { - cluster = "default" - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - application = "default" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - cluster = "default" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig - type = "file" - - nacos { - serverAddr = "localhost" - namespace = "" - group = "SEATA_GROUP" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - app.id = "seata-server" - apollo.meta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - session.timeout = 6000 - connect.timeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/storage.sql b/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/storage.sql deleted file mode 100644 index 9f5521e65..000000000 --- a/springcloud-eureka-feign-mybatis-seata/storage-server/src/main/resources/storage.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE `stock` -( - `id` bigint(11) NOT NULL AUTO_INCREMENT, - `product_id` bigint(11) DEFAULT NULL COMMENT '产品id', - `total` int(11) DEFAULT NULL COMMENT '总库存', - `used` int(11) DEFAULT NULL COMMENT '已用库存', - `residue` int(11) DEFAULT NULL COMMENT '剩余库存', - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; - -INSERT INTO `stock` (`id`, `product_id`, `total`, `used`, `residue`) -VALUES ('1', '1', '100', '0', '100'); diff --git a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/config/DataSourceConfig.java b/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/config/DataSourceConfig.java deleted file mode 100644 index d2631085a..000000000 --- a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/config/DataSourceConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.seata.sample.config; - -import javax.sql.DataSource; - -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -/** - * 数据源配置 - * - * @author HelloWoodes - */ -@Configuration -public class DataSourceConfig { - - @Bean - @ConfigurationProperties(prefix = "spring.datasource") - public DruidDataSource druidDataSource() { - return new DruidDataSource(); - } - - /** - * 需要将 DataSourceProxy 设置为主数据源,否则事务无法回滚 - * - * @param druidDataSource The DruidDataSource - * @return The default datasource - */ - @Primary - @Bean("dataSource") - public DataSource dataSource(DruidDataSource druidDataSource) { - return new DataSourceProxy(druidDataSource); - } -} diff --git a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/controller/AccountController.java b/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/controller/AccountController.java deleted file mode 100644 index a86ee6f09..000000000 --- a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/controller/AccountController.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.seata.sample.controller; - -import java.math.BigDecimal; - -import io.seata.sample.service.AccountService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * Description: - * - * @author fangliangsheng - * @date 2017/12/25 - */ -@RestController -public class AccountController { - - @Autowired - private AccountService accountService; - - @RequestMapping("/debit") - public Boolean debit(String userId, BigDecimal money) { - accountService.debit(userId, money); - - return true; - } -} diff --git a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/entity/Account.java b/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/entity/Account.java deleted file mode 100644 index 308182108..000000000 --- a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/entity/Account.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.seata.sample.entity; - -import java.math.BigDecimal; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.hibernate.annotations.DynamicInsert; -import org.hibernate.annotations.DynamicUpdate; - -@Entity -@Table(name = "account_tbl") -@DynamicUpdate -@DynamicInsert -public class Account { - - @Id - private Long id; - private String userId; - private BigDecimal money; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public BigDecimal getMoney() { - return money; - } - - public void setMoney(BigDecimal money) { - this.money = money; - } -} diff --git a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/service/AccountService.java b/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/service/AccountService.java deleted file mode 100644 index 7781e0d1b..000000000 --- a/springcloud-jpa-seata/account-service/src/main/java/io/seata/sample/service/AccountService.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.seata.sample.service; - -import java.math.BigDecimal; - -import io.seata.sample.entity.Account; -import io.seata.sample.repository.AccountDAO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-05 - */ -@Service -public class AccountService { - - private static final String ERROR_USER_ID = "1002"; - @Autowired - private AccountDAO accountDAO; - - @Transactional(rollbackFor = Exception.class) - public void debit(String userId, BigDecimal num) { - Account account = accountDAO.findByUserId(userId); - account.setMoney(account.getMoney().subtract(num)); - accountDAO.save(account); - - if (ERROR_USER_ID.equals(userId)) { - throw new RuntimeException("account branch exception"); - } - } -} diff --git a/springcloud-jpa-seata/account-service/src/main/resources/application.properties b/springcloud-jpa-seata/account-service/src/main/resources/application.properties deleted file mode 100755 index ad90608c0..000000000 --- a/springcloud-jpa-seata/account-service/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.application.name=account-service -server.port=8083 -spring.datasource.url=jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar?useSSL=false&serverTimezone=UTC -spring.datasource.username=workshop -spring.datasource.password=Workshop123 -spring.jpa.show-sql=true \ No newline at end of file diff --git a/springcloud-jpa-seata/account-service/src/main/resources/file.conf b/springcloud-jpa-seata/account-service/src/main/resources/file.conf deleted file mode 100644 index e38ee8290..000000000 --- a/springcloud-jpa-seata/account-service/src/main/resources/file.conf +++ /dev/null @@ -1,66 +0,0 @@ -transport { - # tcp udt unix-domain-socket - type = "TCP" - #NIO NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the client batch send request enable - enableClientBatchSendRequest = true - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size,will not be used for UDT - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "127.0.0.1:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - reportSuccessEnable = false - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - } - undo { - dataValidation = true - logSerialization = "jackson" - logTable = "undo_log" - } - log { - exceptionRate = 100 - } -} \ No newline at end of file diff --git a/springcloud-jpa-seata/account-service/src/main/resources/registry.conf b/springcloud-jpa-seata/account-service/src/main/resources/registry.conf deleted file mode 100644 index cd2b7ac33..000000000 --- a/springcloud-jpa-seata/account-service/src/main/resources/registry.conf +++ /dev/null @@ -1,79 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "file" - - nacos { - application = "seata-server" - serverAddr = "localhost" - namespace = "" - username = "" - password = "" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - password = "" - timeout = "0" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig - type = "file" - - nacos { - serverAddr = "localhost" - namespace = "" - group = "SEATA_GROUP" - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - appId = "seata-server" - apolloMeta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-jpa-seata/business-service/pom.xml b/springcloud-jpa-seata/business-service/pom.xml deleted file mode 100755 index ba3009863..000000000 --- a/springcloud-jpa-seata/business-service/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - io.seata - springcloud-jpa-seata - 1.1.0 - - 4.0.0 - - business-service - jar - - business-service - Demo project for Spring Boot - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - com.alibaba.cloud - spring-cloud-alibaba-seata - - - io.seata - seata-all - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/controller/BusinessController.java b/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/controller/BusinessController.java deleted file mode 100644 index b174e40d9..000000000 --- a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/controller/BusinessController.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.seata.sample.controller; - -import io.seata.sample.service.BusinessService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class BusinessController { - - @Autowired - private BusinessService businessService; - - /** - * 购买下单,模拟全局事务提交 - * - * @return - */ - @RequestMapping("/purchase/commit") - public Boolean purchaseCommit() { - businessService.purchase("1001", "2001", 1); - return true; - } - - /** - * 购买下单,模拟全局事务回滚 - * - * @return - */ - @RequestMapping("/purchase/rollback") - public Boolean purchaseRollback() { - try { - businessService.purchase("1002", "2001", 1); - } catch (Exception e) { - e.printStackTrace(); - return false; - } - - return true; - } -} diff --git a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/feign/OrderFeignClient.java b/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/feign/OrderFeignClient.java deleted file mode 100644 index e369b65dd..000000000 --- a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/feign/OrderFeignClient.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.seata.sample.feign; - -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-04 - */ -@FeignClient(name = "order-service", url = "127.0.0.1:8082") -public interface OrderFeignClient { - - @GetMapping("/create") - void create(@RequestParam("userId") String userId, @RequestParam("commodityCode") String commodityCode, - @RequestParam("count") Integer count); - -} diff --git a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/service/BusinessService.java b/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/service/BusinessService.java deleted file mode 100644 index 781e46704..000000000 --- a/springcloud-jpa-seata/business-service/src/main/java/io/seata/sample/service/BusinessService.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.seata.sample.service; - -import io.seata.sample.feign.OrderFeignClient; -import io.seata.sample.feign.StockFeignClient; -import io.seata.spring.annotation.GlobalTransactional; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-05 - */ -@Service -public class BusinessService { - - @Autowired - private StockFeignClient stockFeignClient; - @Autowired - private OrderFeignClient orderFeignClient; - - /** - * 减库存,下订单 - * - * @param userId - * @param commodityCode - * @param orderCount - */ - @GlobalTransactional - public void purchase(String userId, String commodityCode, int orderCount) { - stockFeignClient.deduct(commodityCode, orderCount); - - orderFeignClient.create(userId, commodityCode, orderCount); - } -} diff --git a/springcloud-jpa-seata/business-service/src/main/resources/application.properties b/springcloud-jpa-seata/business-service/src/main/resources/application.properties deleted file mode 100755 index b00612703..000000000 --- a/springcloud-jpa-seata/business-service/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.application.name=business-service -server.port=8084 \ No newline at end of file diff --git a/springcloud-jpa-seata/business-service/src/main/resources/file.conf b/springcloud-jpa-seata/business-service/src/main/resources/file.conf deleted file mode 100644 index e38ee8290..000000000 --- a/springcloud-jpa-seata/business-service/src/main/resources/file.conf +++ /dev/null @@ -1,66 +0,0 @@ -transport { - # tcp udt unix-domain-socket - type = "TCP" - #NIO NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the client batch send request enable - enableClientBatchSendRequest = true - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size,will not be used for UDT - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "127.0.0.1:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - reportSuccessEnable = false - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - } - undo { - dataValidation = true - logSerialization = "jackson" - logTable = "undo_log" - } - log { - exceptionRate = 100 - } -} \ No newline at end of file diff --git a/springcloud-jpa-seata/business-service/src/main/resources/registry.conf b/springcloud-jpa-seata/business-service/src/main/resources/registry.conf deleted file mode 100644 index cd2b7ac33..000000000 --- a/springcloud-jpa-seata/business-service/src/main/resources/registry.conf +++ /dev/null @@ -1,79 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "file" - - nacos { - application = "seata-server" - serverAddr = "localhost" - namespace = "" - username = "" - password = "" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - password = "" - timeout = "0" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig - type = "file" - - nacos { - serverAddr = "localhost" - namespace = "" - group = "SEATA_GROUP" - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - appId = "seata-server" - apolloMeta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/config/DataSourceConfig.java b/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/config/DataSourceConfig.java deleted file mode 100644 index d2631085a..000000000 --- a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/config/DataSourceConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.seata.sample.config; - -import javax.sql.DataSource; - -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -/** - * 数据源配置 - * - * @author HelloWoodes - */ -@Configuration -public class DataSourceConfig { - - @Bean - @ConfigurationProperties(prefix = "spring.datasource") - public DruidDataSource druidDataSource() { - return new DruidDataSource(); - } - - /** - * 需要将 DataSourceProxy 设置为主数据源,否则事务无法回滚 - * - * @param druidDataSource The DruidDataSource - * @return The default datasource - */ - @Primary - @Bean("dataSource") - public DataSource dataSource(DruidDataSource druidDataSource) { - return new DataSourceProxy(druidDataSource); - } -} diff --git a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/controller/OrderController.java b/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/controller/OrderController.java deleted file mode 100644 index 8e20a248e..000000000 --- a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/controller/OrderController.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.seata.sample.controller; - -import io.seata.sample.service.OrderService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-04 - */ -@RestController -public class OrderController { - - @Autowired - private OrderService orderService; - - @GetMapping("/create") - public Boolean create(String userId, String commodityCode, Integer count) { - - orderService.create(userId, commodityCode, count); - return true; - } - -} diff --git a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/entity/Order.java b/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/entity/Order.java deleted file mode 100644 index 6da57a18d..000000000 --- a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/entity/Order.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.seata.sample.entity; - -import java.math.BigDecimal; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.hibernate.annotations.DynamicInsert; -import org.hibernate.annotations.DynamicUpdate; - -@Entity -@Table(name = "order_tbl") -@DynamicUpdate -@DynamicInsert -public class Order { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(name = "user_id") - private String userId; - - @Column(name = "commodity_code") - private String commodityCode; - - @Column(name = "money") - private BigDecimal money; - - @Column(name = "count") - private Integer count; - - public Order() { - } - - public Order(String userId, String commodityCode, BigDecimal money, Integer count) { - this.userId = userId; - this.commodityCode = commodityCode; - this.money = money; - this.count = count; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public String getCommodityCode() { - return commodityCode; - } - - public void setCommodityCode(String commodityCode) { - this.commodityCode = commodityCode; - } - - public BigDecimal getMoney() { - return money; - } - - public void setMoney(BigDecimal money) { - this.money = money; - } - - public Integer getCount() { - return count; - } - - public void setCount(Integer count) { - this.count = count; - } -} diff --git a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/feign/AccountFeignClient.java b/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/feign/AccountFeignClient.java deleted file mode 100644 index 088b9e47d..000000000 --- a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/feign/AccountFeignClient.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.seata.sample.feign; - -import java.math.BigDecimal; - -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-04 - */ -@FeignClient(name = "account-service", url = "127.0.0.1:8083") -public interface AccountFeignClient { - - @GetMapping("/debit") - Boolean debit(@RequestParam("userId") String userId, @RequestParam("money") BigDecimal money); -} diff --git a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/repository/OrderDAO.java b/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/repository/OrderDAO.java deleted file mode 100644 index 9481d26ec..000000000 --- a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/repository/OrderDAO.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.seata.sample.repository; - -import io.seata.sample.entity.Order; -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-04 - */ -public interface OrderDAO extends JpaRepository { - -} diff --git a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/service/OrderService.java b/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/service/OrderService.java deleted file mode 100644 index 0fb7f0ed8..000000000 --- a/springcloud-jpa-seata/order-service/src/main/java/io/seata/sample/service/OrderService.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.seata.sample.service; - -import java.math.BigDecimal; - -import io.seata.sample.entity.Order; -import io.seata.sample.feign.AccountFeignClient; -import io.seata.sample.repository.OrderDAO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-04 - */ -@Service -public class OrderService { - - @Autowired - private AccountFeignClient accountFeignClient; - - @Autowired - private OrderDAO orderDAO; - - @Transactional - public void create(String userId, String commodityCode, Integer count) { - - BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5)); - - Order order = new Order(); - order.setUserId(userId); - order.setCommodityCode(commodityCode); - order.setCount(count); - order.setMoney(orderMoney); - - orderDAO.save(order); - - accountFeignClient.debit(userId, orderMoney); - - } - -} diff --git a/springcloud-jpa-seata/order-service/src/main/resources/application.properties b/springcloud-jpa-seata/order-service/src/main/resources/application.properties deleted file mode 100644 index bd0c61be2..000000000 --- a/springcloud-jpa-seata/order-service/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.application.name=order-service -server.port=8082 -spring.datasource.url=jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar?useSSL=false&serverTimezone=UTC -spring.datasource.username=workshop -spring.datasource.password=Workshop123 -spring.jpa.show-sql=true \ No newline at end of file diff --git a/springcloud-jpa-seata/order-service/src/main/resources/file.conf b/springcloud-jpa-seata/order-service/src/main/resources/file.conf deleted file mode 100644 index e38ee8290..000000000 --- a/springcloud-jpa-seata/order-service/src/main/resources/file.conf +++ /dev/null @@ -1,66 +0,0 @@ -transport { - # tcp udt unix-domain-socket - type = "TCP" - #NIO NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the client batch send request enable - enableClientBatchSendRequest = true - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size,will not be used for UDT - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "127.0.0.1:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - reportSuccessEnable = false - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - } - undo { - dataValidation = true - logSerialization = "jackson" - logTable = "undo_log" - } - log { - exceptionRate = 100 - } -} \ No newline at end of file diff --git a/springcloud-jpa-seata/order-service/src/main/resources/registry.conf b/springcloud-jpa-seata/order-service/src/main/resources/registry.conf deleted file mode 100644 index cd2b7ac33..000000000 --- a/springcloud-jpa-seata/order-service/src/main/resources/registry.conf +++ /dev/null @@ -1,79 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "file" - - nacos { - application = "seata-server" - serverAddr = "localhost" - namespace = "" - username = "" - password = "" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - password = "" - timeout = "0" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig - type = "file" - - nacos { - serverAddr = "localhost" - namespace = "" - group = "SEATA_GROUP" - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - appId = "seata-server" - apolloMeta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-jpa-seata/pom.xml b/springcloud-jpa-seata/pom.xml deleted file mode 100755 index a31e4ec5a..000000000 --- a/springcloud-jpa-seata/pom.xml +++ /dev/null @@ -1,180 +0,0 @@ - - - 4.0.0 - - io.seata - springcloud-jpa-seata - 1.1.0 - seata-sample - Demo project for Seata - pom - - - 1.4.2 - UTF-8 - 1.8 - 1.8 - 1.8 - - - - account-service - order-service - stock-service - business-service - - - - - - org.springframework.cloud - spring-cloud-dependencies - Finchley.BUILD-SNAPSHOT - pom - import - - - org.springframework.boot - spring-boot-dependencies - 2.0.0.RELEASE - pom - import - - - com.alibaba - druid-spring-boot-starter - 1.1.10 - - - com.alibaba.cloud - spring-cloud-alibaba-seata - 2.0.0.RELEASE - - - io.seata - seata-all - - - - - io.seata - seata-all - ${seata.version} - - - org.springframework - spring-context - 5.0.4.RELEASE - - - mysql - mysql-connector-java - 8.0.11 - - - org.springframework.cloud - spring-cloud-starter-openfeign - 2.0.0.RELEASE - - - org.springframework.cloud - spring-cloud-starter-netflix-ribbon - 2.0.0.RELEASE - - - - - - - spring-snapshot - Spring Snapshot Repository - https://repo.spring.io/snapshot - - true - - - - mvnrepository - mvnrepository - http://www.mvnrepository.com/ - default - - true - - - true - - - - sonatype - sonatype - http://oss.sonatype.org/ - default - - true - - - true - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.0 - - ${maven.compiler.source} - ${maven.compiler.target} - - - - org.apache.maven.plugins - maven-pmd-plugin - 3.8 - - ${project.build.sourceEncoding} - 2 - true - - rulesets/java/ali-comment.xml - rulesets/java/ali-concurrent.xml - rulesets/java/ali-constant.xml - rulesets/java/ali-exception.xml - rulesets/java/ali-flowcontrol.xml - rulesets/java/ali-naming.xml - rulesets/java/ali-oop.xml - rulesets/java/ali-orm.xml - rulesets/java/ali-other.xml - rulesets/java/ali-set.xml - - - - - verify - - check - - - - - - com.alibaba.p3c - p3c-pmd - 1.3.6 - - - - - - - diff --git a/springcloud-jpa-seata/sql/all_in_one.sql b/springcloud-jpa-seata/sql/all_in_one.sql deleted file mode 100644 index d88c8eaba..000000000 --- a/springcloud-jpa-seata/sql/all_in_one.sql +++ /dev/null @@ -1,101 +0,0 @@ -# -Account -DROP SCHEMA IF EXISTS db_account; -CREATE SCHEMA db_account; -USE -db_account; - -CREATE TABLE `account_tbl` -( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `user_id` VARCHAR(255) DEFAULT NULL, - `money` INT(11) DEFAULT 0, - PRIMARY KEY (`id`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -INSERT INTO account_tbl (id, user_id, money) -VALUES (1, '1001', 10000); -INSERT INTO account_tbl (id, user_id, money) -VALUES (2, '1002', 10000); - -CREATE TABLE `undo_log` -( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `branch_id` bigint(20) NOT NULL, - `xid` varchar(100) NOT NULL, - `context` varchar(128) NOT NULL, - `rollback_info` longblob NOT NULL, - `log_status` int(11) NOT NULL, - `log_created` datetime NOT NULL, - `log_modified` datetime NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; - -# -Order -DROP SCHEMA IF EXISTS db_order; -CREATE SCHEMA db_order; -USE -db_order; - -CREATE TABLE `order_tbl` -( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `user_id` VARCHAR(255) DEFAULT NULL, - `commodity_code` VARCHAR(255) DEFAULT NULL, - `count` INT(11) DEFAULT '0', - `money` INT(11) DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - -CREATE TABLE `undo_log` -( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `branch_id` bigint(20) NOT NULL, - `xid` varchar(100) NOT NULL, - `context` varchar(128) NOT NULL, - `rollback_info` longblob NOT NULL, - `log_status` int(11) NOT NULL, - `log_created` datetime NOT NULL, - `log_modified` datetime NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; - -# -Stock -DROP SCHEMA IF EXISTS db_stock; -CREATE SCHEMA db_stock; -USE -db_stock; - -CREATE TABLE `stock_tbl` -( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `commodity_code` VARCHAR(255) DEFAULT NULL, - `count` INT(11) DEFAULT '0', - PRIMARY KEY (`id`), - UNIQUE KEY `commodity_code` (`commodity_code`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8; - - -INSERT INTO stock_tbl (id, commodity_code, count) -VALUES (1, '2001', 1000); - -CREATE TABLE `undo_log` -( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `branch_id` bigint(20) NOT NULL, - `xid` varchar(100) NOT NULL, - `context` varchar(128) NOT NULL, - `rollback_info` longblob NOT NULL, - `log_status` int(11) NOT NULL, - `log_created` datetime NOT NULL, - `log_modified` datetime NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/StockApplication.java b/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/StockApplication.java deleted file mode 100644 index 3fd1cf867..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/StockApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.seata.sample; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - -@SpringBootApplication -@EnableJpaRepositories -public class StockApplication { - - public static void main(String[] args) { - SpringApplication.run(StockApplication.class, args); - } - -} diff --git a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/config/DataSourceConfig.java b/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/config/DataSourceConfig.java deleted file mode 100644 index d2631085a..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/config/DataSourceConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.seata.sample.config; - -import javax.sql.DataSource; - -import com.alibaba.druid.pool.DruidDataSource; - -import io.seata.rm.datasource.DataSourceProxy; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -/** - * 数据源配置 - * - * @author HelloWoodes - */ -@Configuration -public class DataSourceConfig { - - @Bean - @ConfigurationProperties(prefix = "spring.datasource") - public DruidDataSource druidDataSource() { - return new DruidDataSource(); - } - - /** - * 需要将 DataSourceProxy 设置为主数据源,否则事务无法回滚 - * - * @param druidDataSource The DruidDataSource - * @return The default datasource - */ - @Primary - @Bean("dataSource") - public DataSource dataSource(DruidDataSource druidDataSource) { - return new DataSourceProxy(druidDataSource); - } -} diff --git a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/controller/StockController.java b/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/controller/StockController.java deleted file mode 100644 index fe0052250..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/controller/StockController.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.seata.sample.controller; - -import io.seata.sample.service.StockService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019/3/28 - */ -@RestController -public class StockController { - - @Autowired - private StockService stockService; - - @GetMapping(path = "/deduct") - public Boolean deduct(String commodityCode, Integer count) { - stockService.deduct(commodityCode, count); - return true; - } -} diff --git a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/entity/Stock.java b/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/entity/Stock.java deleted file mode 100644 index 85631bd7a..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/entity/Stock.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.seata.sample.entity; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.hibernate.annotations.DynamicInsert; -import org.hibernate.annotations.DynamicUpdate; - -@Entity -@Table(name = "stock_tbl") -@DynamicUpdate -@DynamicInsert -public class Stock { - - @Id - private Long id; - private String commodityCode; - private Integer count; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getCommodityCode() { - return commodityCode; - } - - public void setCommodityCode(String commodityCode) { - this.commodityCode = commodityCode; - } - - public Integer getCount() { - return count; - } - - public void setCount(Integer count) { - this.count = count; - } -} diff --git a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/repository/StockDAO.java b/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/repository/StockDAO.java deleted file mode 100644 index d1cceb3cc..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/repository/StockDAO.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.seata.sample.repository; - -import io.seata.sample.entity.Stock; -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-04 - */ -public interface StockDAO extends JpaRepository { - - Stock findByCommodityCode(String commodityCode); - -} diff --git a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/service/StockService.java b/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/service/StockService.java deleted file mode 100644 index 4af497798..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/java/io/seata/sample/service/StockService.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.seata.sample.service; - -import io.seata.sample.entity.Stock; -import io.seata.sample.repository.StockDAO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * Description: - * - * @author fangliangsheng - * @date 2019-04-04 - */ -@Service -public class StockService { - - @Autowired - private StockDAO stockDAO; - - @Transactional - public void deduct(String commodityCode, int count) { - Stock stock = stockDAO.findByCommodityCode(commodityCode); - stock.setCount(stock.getCount() - count); - - stockDAO.save(stock); - } -} diff --git a/springcloud-jpa-seata/stock-service/src/main/resources/application.properties b/springcloud-jpa-seata/stock-service/src/main/resources/application.properties deleted file mode 100644 index 75fb604a0..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.application.name=stock-service -server.port=8081 -spring.datasource.url=jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar?useSSL=false&serverTimezone=UTC -spring.datasource.username=workshop -spring.datasource.password=Workshop123 -spring.jpa.show-sql=true \ No newline at end of file diff --git a/springcloud-jpa-seata/stock-service/src/main/resources/file.conf b/springcloud-jpa-seata/stock-service/src/main/resources/file.conf deleted file mode 100644 index e38ee8290..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/resources/file.conf +++ /dev/null @@ -1,66 +0,0 @@ -transport { - # tcp udt unix-domain-socket - type = "TCP" - #NIO NATIVE - server = "NIO" - #enable heartbeat - heartbeat = true - # the client batch send request enable - enableClientBatchSendRequest = true - #thread factory for netty - threadFactory { - bossThreadPrefix = "NettyBoss" - workerThreadPrefix = "NettyServerNIOWorker" - serverExecutorThread-prefix = "NettyServerBizHandler" - shareBossWorker = false - clientSelectorThreadPrefix = "NettyClientSelector" - clientSelectorThreadSize = 1 - clientWorkerThreadPrefix = "NettyClientWorkerThread" - # netty boss thread size,will not be used for UDT - bossThreadSize = 1 - #auto default pin or 8 - workerThreadSize = "default" - } - shutdown { - # when destroy server, wait seconds - wait = 3 - } - serialization = "seata" - compressor = "none" -} -service { - #transaction service group mapping - vgroupMapping.my_test_tx_group = "default" - #only support when registry.type=file, please don't set multiple addresses - default.grouplist = "127.0.0.1:8091" - #degrade, current not support - enableDegrade = false - #disable seata - disableGlobalTransaction = false -} - -client { - rm { - asyncCommitBufferLimit = 10000 - lock { - retryInterval = 10 - retryTimes = 30 - retryPolicyBranchRollbackOnConflict = true - } - reportRetryCount = 5 - tableMetaCheckEnable = false - reportSuccessEnable = false - } - tm { - commitRetryCount = 5 - rollbackRetryCount = 5 - } - undo { - dataValidation = true - logSerialization = "jackson" - logTable = "undo_log" - } - log { - exceptionRate = 100 - } -} \ No newline at end of file diff --git a/springcloud-jpa-seata/stock-service/src/main/resources/registry.conf b/springcloud-jpa-seata/stock-service/src/main/resources/registry.conf deleted file mode 100644 index cd2b7ac33..000000000 --- a/springcloud-jpa-seata/stock-service/src/main/resources/registry.conf +++ /dev/null @@ -1,79 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "file" - - nacos { - application = "seata-server" - serverAddr = "localhost" - namespace = "" - username = "" - password = "" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = "0" - password = "" - timeout = "0" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3、springCloudConfig - type = "file" - - nacos { - serverAddr = "localhost" - namespace = "" - group = "SEATA_GROUP" - username = "" - password = "" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - appId = "seata-server" - apolloMeta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-nacos-seata/order-service/pom.xml b/springcloud-nacos-seata/order-service/pom.xml deleted file mode 100644 index 63bf228bb..000000000 --- a/springcloud-nacos-seata/order-service/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - io.seata - springcloud-nacos-seata - 1.1.0 - ../pom.xml - - 4.0.0 - io.seata - - nacos-order-service - jar - 1.1.0 - - - - - - - - io.github.openfeign - feign-httpclient - 11.8 - - - io.github.openfeign - feign-core - 11.8 - - - - - \ No newline at end of file diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/OrderServiceApplication.java b/springcloud-nacos-seata/order-service/src/main/java/com/work/order/OrderServiceApplication.java deleted file mode 100644 index 854ce4cf9..000000000 --- a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/OrderServiceApplication.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.order; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.openfeign.EnableFeignClients; - -@EnableDiscoveryClient -@EnableFeignClients -@SpringBootApplication(scanBasePackages = {"com.work"}) -public class OrderServiceApplication { - - public static void main(String[] args) { - SpringApplication.run(OrderServiceApplication.class, args); - } - -} diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/controller/OrderController.java b/springcloud-nacos-seata/order-service/src/main/java/com/work/order/controller/OrderController.java deleted file mode 100644 index c39ab2f7b..000000000 --- a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/controller/OrderController.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.order.controller; - -import com.work.order.feign.StockFeignClient; -import com.work.order.service.OrderService; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; - -/** - * Program Name: springcloud-nacos-seata - *

- * Description: - *

- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@RestController -@RequestMapping("order") -public class OrderController { - - @Resource - private OrderService orderService; - @Resource - private StockFeignClient stockFeignClient; - - /** - * 下单:插入订单表、扣减库存,模拟回滚 - * - * @return - */ - @RequestMapping("/placeOrder/commit") - public Boolean placeOrderCommit() { - - orderService.placeOrder("1", "product-1", 1); - return true; - } - - /** - * 下单:插入订单表、扣减库存,模拟回滚 - * - * @return - */ - @RequestMapping("/placeOrder/rollback") - public Boolean placeOrderRollback() { - // product-2 扣库存时模拟了一个业务异常, - orderService.placeOrder("1", "product-2", 1); - return true; - } - - @RequestMapping("/placeOrder") - public Boolean placeOrder(String userId, String commodityCode, Integer count) { - orderService.placeOrder(userId, commodityCode, count); - return true; - } -} diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/model/Order.java b/springcloud-nacos-seata/order-service/src/main/java/com/work/order/model/Order.java deleted file mode 100644 index abfdd0d6c..000000000 --- a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/model/Order.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.order.model; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.math.BigDecimal; - -/** - * Program Name: springcloud-nacos-seata - *

- * Description: - *

- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@Data -@Accessors(chain = true) -@TableName("order_tbl") -public class Order { - - @TableId(type = IdType.AUTO) - private Integer id; - private String userId; - private String commodityCode; - private Integer count; - private BigDecimal money; - -} diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/repository/OrderDAO.java b/springcloud-nacos-seata/order-service/src/main/java/com/work/order/repository/OrderDAO.java deleted file mode 100644 index 2a37bb111..000000000 --- a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/repository/OrderDAO.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.order.repository; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.work.order.model.Order; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Repository; - -/** - * Program Name: springcloud-nacos-seata - *

- * Description: - *

- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@Mapper -@Repository -public interface OrderDAO extends BaseMapper { - -} diff --git a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/service/OrderService.java b/springcloud-nacos-seata/order-service/src/main/java/com/work/order/service/OrderService.java deleted file mode 100644 index 537f25e25..000000000 --- a/springcloud-nacos-seata/order-service/src/main/java/com/work/order/service/OrderService.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.order.service; - -import com.work.order.feign.AccountFeignClient; -import com.work.order.feign.StockFeignClient; -import com.work.order.model.Order; -import com.work.order.repository.OrderDAO; -import io.seata.spring.annotation.GlobalTransactional; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; - -import java.math.BigDecimal; - -/** - * Program Name: springcloud-nacos-seata - *

- * Description: - *

- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@Service -public class OrderService { - - @Resource - private AccountFeignClient accountFeignClient; - @Resource - private StockFeignClient stockFeignClient; - @Resource - private OrderDAO orderDAO; - - /** - * 下单:创建订单、减库存,涉及到两个服务 - * - * @param userId - * @param commodityCode - * @param count - */ - @GlobalTransactional - @Transactional(rollbackFor = Exception.class) - public void placeOrder(String userId, String commodityCode, Integer count) { - BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5)); - Order order = new Order().setUserId(userId).setCommodityCode(commodityCode).setCount(count).setMoney( - orderMoney); - orderDAO.insert(order); - stockFeignClient.deduct(commodityCode, count); - - } - - @Transactional(rollbackFor = Exception.class) - public void create(String userId, String commodityCode, Integer count) { - - BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5)); - - Order order = new Order().setUserId(userId).setCommodityCode(commodityCode).setCount(count).setMoney( - orderMoney); - orderDAO.insert(order); - - accountFeignClient.reduce(userId, orderMoney); - - } - -} diff --git a/springcloud-nacos-seata/order-service/src/main/resources/application.properties b/springcloud-nacos-seata/order-service/src/main/resources/application.properties deleted file mode 100644 index 64afb8422..000000000 --- a/springcloud-nacos-seata/order-service/src/main/resources/application.properties +++ /dev/null @@ -1,12 +0,0 @@ -spring.application.name=order-service -server.port=9091 -# Nacos 注册中心地址 -spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -# seata 服务分组,要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 -spring.cloud.alibaba.seata.tx-service-group=my_test_tx_group -logging.level.io.seata=debug -# 数据源配置 -spring.datasource.url=jdbc:mysql://localhost:3306/seata_order?allowMultiQueries=true -spring.datasource.driverClassName=com.mysql.jdbc.Driver -spring.datasource.username=root -spring.datasource.password=123456 \ No newline at end of file diff --git a/springcloud-nacos-seata/order-service/src/main/resources/registry.conf b/springcloud-nacos-seata/order-service/src/main/resources/registry.conf deleted file mode 100644 index 0c46e26a1..000000000 --- a/springcloud-nacos-seata/order-service/src/main/resources/registry.conf +++ /dev/null @@ -1,89 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "nacos" - - nacos { - application = "seata-server" - serverAddr = "127.0.0.1:8848" - group = "SEATA_GROUP" - namespace = "" - cluster = "default" - username = "nacos" - password = "nacos" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - application = "default" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = 0 - password = "" - cluster = "default" - timeout = 0 - } - zk { - cluster = "default" - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - consul { - cluster = "default" - serverAddr = "127.0.0.1:8500" - } - etcd3 { - cluster = "default" - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - application = "default" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - cluster = "default" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3 - type = "nacos" - - nacos { - serverAddr = "127.0.0.1:8848" - namespace = "" - group = "SEATA_GROUP" - username = "nacos" - password = "nacos" - dataId = "seataServer.properties" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - appId = "seata-server" - apolloMeta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-nacos-seata/pom.xml b/springcloud-nacos-seata/pom.xml deleted file mode 100644 index 0451df4c0..000000000 --- a/springcloud-nacos-seata/pom.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - 4.0.0 - pom - io.seata - springcloud-nacos-seata - 1.1.0 - - spring-cloud-alibaba-samples - Spring Cloud Alibaba + Nacos + OpenFeign + Seata - - order-service - stock-service - - - - 1.8 - 2.2.7.RELEASE - 2.2.12.RELEASE - 1.18.8 - - UTF-8 - true - 3.0.1 - 2.22.1 - 1.4.2 - 3.3.0 - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-seata - ${spring-cloud-alibaba.version} - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-actuator - - - - org.projectlombok - lombok - - - - - com.baomidou - mybatis-plus-boot-starter - ${mybatis-plus-boot-starter.version} - - - - - - org.mybatis.generator - mybatis-generator-core - 1.3.7 - - - - - mysql - mysql-connector-java - - - - io.github.openfeign - feign-slf4j - 11.8 - - - - log4j - log4j - 1.2.17 - - - org.apache.commons - commons-lang3 - - - - - io.seata - seata-spring-boot-starter - 1.4.2 - - - - - org.springframework.cloud - spring-cloud-starter-openfeign - 2.2.6.RELEASE - - - - - - - - org.springframework.boot - spring-boot-dependencies - ${springboot.version} - pom - import - - - - - com.alibaba.cloud - spring-cloud-alibaba-dependencies - ${spring-cloud-alibaba.version} - pom - import - - - - org.projectlombok - lombok - ${lombok.version} - - - - mysql - mysql-connector-java - 8.0.28 - - - - - com.alibaba.spring - spring-context-support - 1.0.11 - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - UTF-8 - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - org.apache.maven.plugins - maven-surefire-plugin - - true - - ${maven-surefire-plugin.version} - - - - diff --git a/springcloud-nacos-seata/stock-service/pom.xml b/springcloud-nacos-seata/stock-service/pom.xml deleted file mode 100644 index 11f23ff67..000000000 --- a/springcloud-nacos-seata/stock-service/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - io.seata - springcloud-nacos-seata - 1.1.0 - ../pom.xml - - 4.0.0 - io.seata - - nacos-stock-service - jar - 1.1.0 - - - - - - - - io.github.openfeign - feign-httpclient - 11.8 - - - io.github.openfeign - feign-core - 11.8 - - - - - \ No newline at end of file diff --git a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/StockServiceApplication.java b/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/StockServiceApplication.java deleted file mode 100644 index f1f66ae8b..000000000 --- a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/StockServiceApplication.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.stock; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.openfeign.EnableFeignClients; - -@EnableDiscoveryClient -@EnableFeignClients -@SpringBootApplication(scanBasePackages = {"com.work"}) -public class StockServiceApplication { - - public static void main(String[] args) { - SpringApplication.run(StockServiceApplication.class, args); - } - -} diff --git a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/controller/StockController.java b/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/controller/StockController.java deleted file mode 100644 index 6e43fbd85..000000000 --- a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/controller/StockController.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.stock.controller; - -import com.work.stock.service.StockService; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; - -/** - * Program Name: springcloud-nacos-seata - *

- * Description: - *

- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@RestController -@RequestMapping("stock") -public class StockController { - - @Resource - private StockService stockService; - - /** - * 减库存 - * - * @param commodityCode 商品代码 - * @param count 数量 - * @return - */ - @RequestMapping(path = "/deduct") - public Boolean deduct(String commodityCode, Integer count) { - stockService.deduct(commodityCode, count); - return true; - } - -} diff --git a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/entity/Stock.java b/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/entity/Stock.java deleted file mode 100644 index d7fea2ff8..000000000 --- a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/entity/Stock.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.stock.entity; - -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * Program Name: springcloud-nacos-seata - *

- * Description: - *

- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@Data -@Accessors(chain = true) -@TableName("stock_tbl") -public class Stock { - - private Long id; - private String commodityCode; - private Long count; - -} diff --git a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/service/StockService.java b/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/service/StockService.java deleted file mode 100644 index 89fb964a8..000000000 --- a/springcloud-nacos-seata/stock-service/src/main/java/com/work/stock/service/StockService.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 1999-2021 Seata.io Group. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.work.stock.service; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.work.stock.entity.Stock; -import com.work.stock.repository.StockDAO; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; - -/** - * Program Name: springcloud-nacos-seata - *

- * Description: - *

- * - * @author zhangjianwei - * @version 1.0 - * @date 2019/8/28 4:05 PM - */ -@Service -public class StockService { - - @Resource - private StockDAO stockDAO; - - /** - * 减库存 - * - * @param commodityCode - * @param count - */ - @Transactional(rollbackFor = Exception.class) - public void deduct(String commodityCode, int count) { - if (commodityCode.equals("product-2")) { - throw new RuntimeException("异常:模拟业务异常:stock branch exception"); - } - - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.setEntity(new Stock().setCommodityCode(commodityCode)); - Stock stock = stockDAO.selectOne(wrapper); - stock.setCount(stock.getCount() - count); - - stockDAO.updateById(stock); - } -} diff --git a/springcloud-nacos-seata/stock-service/src/main/resources/application.properties b/springcloud-nacos-seata/stock-service/src/main/resources/application.properties deleted file mode 100644 index 6b828cb90..000000000 --- a/springcloud-nacos-seata/stock-service/src/main/resources/application.properties +++ /dev/null @@ -1,12 +0,0 @@ -spring.application.name=stock-service -server.port=9092 -# Nacos 注册中心地址 -spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -# seata 服务分组,要与服务端nacos-config.txt中service.vgroup_mapping的后缀对应 -spring.cloud.alibaba.seata.tx-service-group=my_test_tx_group -logging.level.io.seata=debug -# 数据源配置 -spring.datasource.url=jdbc:mysql://localhost:3306/seata_stock?allowMultiQueries=true -spring.datasource.driverClassName=com.mysql.jdbc.Driver -spring.datasource.username=root -spring.datasource.password=123456 \ No newline at end of file diff --git a/springcloud-nacos-seata/stock-service/src/main/resources/registry.conf b/springcloud-nacos-seata/stock-service/src/main/resources/registry.conf deleted file mode 100644 index 0c46e26a1..000000000 --- a/springcloud-nacos-seata/stock-service/src/main/resources/registry.conf +++ /dev/null @@ -1,89 +0,0 @@ -registry { - # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa - type = "nacos" - - nacos { - application = "seata-server" - serverAddr = "127.0.0.1:8848" - group = "SEATA_GROUP" - namespace = "" - cluster = "default" - username = "nacos" - password = "nacos" - } - eureka { - serviceUrl = "http://localhost:8761/eureka" - application = "default" - weight = "1" - } - redis { - serverAddr = "localhost:6379" - db = 0 - password = "" - cluster = "default" - timeout = 0 - } - zk { - cluster = "default" - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - consul { - cluster = "default" - serverAddr = "127.0.0.1:8500" - } - etcd3 { - cluster = "default" - serverAddr = "http://localhost:2379" - } - sofa { - serverAddr = "127.0.0.1:9603" - application = "default" - region = "DEFAULT_ZONE" - datacenter = "DefaultDataCenter" - cluster = "default" - group = "SEATA_GROUP" - addressWaitTime = "3000" - } - file { - name = "file.conf" - } -} - -config { - # file、nacos 、apollo、zk、consul、etcd3 - type = "nacos" - - nacos { - serverAddr = "127.0.0.1:8848" - namespace = "" - group = "SEATA_GROUP" - username = "nacos" - password = "nacos" - dataId = "seataServer.properties" - } - consul { - serverAddr = "127.0.0.1:8500" - } - apollo { - appId = "seata-server" - apolloMeta = "http://192.168.1.204:8801" - namespace = "application" - } - zk { - serverAddr = "127.0.0.1:2181" - sessionTimeout = 6000 - connectTimeout = 2000 - username = "" - password = "" - } - etcd3 { - serverAddr = "http://localhost:2379" - } - file { - name = "file.conf" - } -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/client/ProductClient.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/client/ProductClient.java deleted file mode 100644 index 919895937..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/client/ProductClient.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.seata.order.client; - -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.PutMapping; - -@FeignClient("product-server") -public interface ProductClient { - - @PutMapping("/minus/stock") - public Void minusStock(); - -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/controller/OrderController.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/controller/OrderController.java deleted file mode 100644 index a21f9862f..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/controller/OrderController.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.seata.order.controller; - -import io.seata.order.service.OrderService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class OrderController { - - @Autowired - private OrderService orderService; - - @PostMapping("/seata/test") - public ResponseEntity seataDemo(Boolean hasError) { - orderService.seataDemo(hasError); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } - -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/entity/Order.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/entity/Order.java deleted file mode 100644 index 373621d53..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/entity/Order.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.seata.order.entity; - -import java.time.LocalDateTime; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; - -@Data -@TableName("order_info") -public class Order { - - @TableId(type = IdType.ASSIGN_ID) - private Long id; - - private String orderName; - - private Long productId; - - private Integer buyNum; - - private LocalDateTime createTime; - - private LocalDateTime updateTime; - -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/mapper/OrderMapper.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/mapper/OrderMapper.java deleted file mode 100644 index 201536071..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/mapper/OrderMapper.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.seata.order.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import io.seata.order.entity.Order; - -public interface OrderMapper extends BaseMapper {} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/service/OrderService.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/service/OrderService.java deleted file mode 100644 index 182fadf34..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/java/io/seata/order/service/OrderService.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.seata.order.service; - -import io.seata.order.client.ProductClient; -import io.seata.order.entity.Order; -import io.seata.order.mapper.OrderMapper; -import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType; -import org.apache.shardingsphere.transaction.core.TransactionType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -public class OrderService { - - @Autowired - private ProductClient productClient; - - @Autowired - private OrderMapper orderMapper; - - //这里切记不要加@GlobalTransactional - @Transactional - @ShardingTransactionType(TransactionType.BASE) - public void seataDemo(Boolean hasError) { - //下单操作 - Order order = new Order(); - order.setOrderName("测试数据"); - order.setBuyNum(2); - orderMapper.insert(order); - - //减库存(这里参数什么的就自己脑补了) - productClient.minusStock(); - - //异常模拟 - if (hasError) { - int i = 1 / 0; - } - } -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/resources/application.properties b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/resources/application.properties deleted file mode 100644 index 3d19e2fa9..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/resources/application.properties +++ /dev/null @@ -1,39 +0,0 @@ -#订单微服务服务信息 -server.port=8001 -spring.application.name=order-server -#订单微服务注册中心 -spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -spring.cloud.nacos.discovery.group=LTF_GROUP -#sharding-jdbc数据源配置 -spring.shardingsphere.datasource.names=ds0,ds1 -spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource -spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.cj.jdbc.Driver -spring.shardingsphere.datasource.ds0.jdbc-url=jdbc:mysql://127.0.0.1:3306/seata_order_0?serverTimezone=UTC&characterEncoding=utf8 -spring.shardingsphere.datasource.ds0.username=root -spring.shardingsphere.datasource.ds0.password=root -spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource -spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.cj.jdbc.Driver -spring.shardingsphere.datasource.ds1.jdbc-url=jdbc:mysql://127.0.0.1:3306/seata_order_1?serverTimezone=UTC&characterEncoding=utf8 -spring.shardingsphere.datasource.ds1.username=root -spring.shardingsphere.datasource.ds1.password=root -#sharding-jdbc分片配置 -spring.shardingsphere.sharding.default-database-strategy.inline.sharding-column=id -spring.shardingsphere.sharding.default-database-strategy.inline.algorithm-expression=ds$->{id % 2} -spring.shardingsphere.sharding.tables.order_info.actual-data-nodes=ds$->{0..1}.order_info_$->{0..2} -spring.shardingsphere.sharding.tables.order_info.table-strategy.inline.sharding-column=id -spring.shardingsphere.sharding.tables.order_info.table-strategy.inline.algorithm-expression=order_info_$->{id % 3} -#sharding-jdbc显示最终SQL -spring.shardingsphere.props.sql.show=true -#mybatis-plus配置 -mybatis-plus.configuration.map-underscore-to-camel-case=true -logging.level.io.seata=debug -# SEATA配置 -seata.application-id=order-server -seata.tx-service-group=ltf_tx_group -seata.config.type=nacos -seata.config.nacos.server-addr=127.0.0.1:8848 -seata.config.nacos.group=SEATA_GROUP -seata.config.nacos.username=nacos -seata.config.nacos.password=nacos -seata.enable-auto-data-source-proxy=false -spring.main.allow-bean-definition-overriding=true diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/resources/seata.conf b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/resources/seata.conf deleted file mode 100644 index a925b9bbf..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-order-sample/src/main/resources/seata.conf +++ /dev/null @@ -1,4 +0,0 @@ -client { - application.id = order-server - transaction.service.group = ltf_tx_group -} \ No newline at end of file diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/ProductApplication.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/ProductApplication.java deleted file mode 100644 index f0a50e9bb..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/ProductApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.seata; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -@MapperScan("io.seata.product.mapper") -public class ProductApplication { - public static void main(String[] args) { - SpringApplication.run(ProductApplication.class, args); - } -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/controller/ProductController.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/controller/ProductController.java deleted file mode 100644 index 460063136..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/controller/ProductController.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.seata.product.controller; - -import io.seata.product.service.ProductService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class ProductController { - - @Autowired - private ProductService productService; - - @PutMapping("/minus/stock") - public ResponseEntity minusStock() { - productService.minusStock(); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } - -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/entity/Product.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/entity/Product.java deleted file mode 100644 index 5706e070b..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/entity/Product.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.seata.product.entity; - -import java.time.LocalDateTime; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; - -@Data -@TableName("product_info") -public class Product { - @TableId(type = IdType.ASSIGN_ID) - private Long id; - - private String productName; - - private Integer stock; - - private LocalDateTime createTime; - - private LocalDateTime updateTime; -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/mapper/ProductMapper.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/mapper/ProductMapper.java deleted file mode 100644 index 2a1abf8f3..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/mapper/ProductMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.seata.product.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import io.seata.product.entity.Product; -import org.apache.ibatis.annotations.Update; - -public interface ProductMapper extends BaseMapper { - - @Update("update product_info set stock = stock-1") - void minusStock(); -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/service/ProductService.java b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/service/ProductService.java deleted file mode 100644 index 0d1c77e0f..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/java/io/seata/product/service/ProductService.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.seata.product.service; - -import io.seata.product.mapper.ProductMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -public class ProductService { - - @Autowired - private ProductMapper productMapper; - - public void minusStock() { - productMapper.minusStock(); - } -} diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/resources/application.properties b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/resources/application.properties deleted file mode 100644 index 0bea7e734..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/resources/application.properties +++ /dev/null @@ -1,60 +0,0 @@ -#产品微服务服务信息 -server.port=8002 -spring.application.name=product-server -#产品微服务注册中心 -spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -spring.cloud.nacos.discovery.group=LTF_GROUP -#数据源配置 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.datasource.url=jdbc:mysql://127.0.0.1:3306/seata_product?serverTimezone=UTC&characterEncoding=utf8 -spring.datasource.username=root -spring.datasource.password=root -#mybatis-plus配置 -mybatis-plus.configuration.map-underscore-to-camel-case=true -logging.level.com.qmp=debug -# seata 分布式事务配置 -seata.application-id=product-server -seata.tx-service-group=ltf_tx_group -seata.config.type=nacos -seata.config.nacos.server-addr=127.0.0.1:8848 -seata.config.nacos.group=SEATA_GROUP -seata.config.nacos.username=nacos -seata.config.nacos.password=nacos -spring.main.allow-bean-definition-overriding=true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/resources/seata.conf b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/resources/seata.conf deleted file mode 100644 index 70daae533..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/seata-product-sample/src/main/resources/seata.conf +++ /dev/null @@ -1,4 +0,0 @@ -client { - application.id = product-server - transaction.service.group = ltf_tx_group -} \ No newline at end of file diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_order_0.sql b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_order_0.sql deleted file mode 100644 index 78bbc127c..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_order_0.sql +++ /dev/null @@ -1,95 +0,0 @@ -/* -SQLyog Ultimate v13.1.1 (64 bit) -MySQL - 8.0.22 : Database - seata_order_0 -********************************************************************* -*/ - -/*!40101 SET NAMES utf8 */; - -/*!40101 SET SQL_MODE=''*/; - -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -CREATE -DATABASE /*!32312 IF NOT EXISTS*/`seata_order_0` /*!40100 DEFAULT CHARACTER SET utf8 */ /*!80016 DEFAULT ENCRYPTION='N' */; - -USE -`seata_order_0`; - -/*Table structure for table `order_info_0` */ - -DROP TABLE IF EXISTS `order_info_0`; - -CREATE TABLE `order_info_0` -( - `id` bigint NOT NULL COMMENT '订单id,采用分布式id', - `order_name` varchar(128) DEFAULT NULL COMMENT '订单名称', - `product_id` bigint DEFAULT NULL COMMENT '购买产品id', - `buy_num` int DEFAULT NULL COMMENT '购买数量', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='订单表'; - -/*Data for the table `order_info_0` */ - -/*Table structure for table `order_info_1` */ - -DROP TABLE IF EXISTS `order_info_1`; - -CREATE TABLE `order_info_1` -( - `id` bigint NOT NULL COMMENT '订单id,采用分布式id', - `order_name` varchar(128) DEFAULT NULL COMMENT '订单名称', - `product_id` bigint DEFAULT NULL COMMENT '购买产品id', - `buy_num` int DEFAULT NULL COMMENT '购买数量', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='订单表'; - -/*Data for the table `order_info_1` */ - -/*Table structure for table `order_info_2` */ - -DROP TABLE IF EXISTS `order_info_2`; - -CREATE TABLE `order_info_2` -( - `id` bigint NOT NULL COMMENT '订单id,采用分布式id', - `order_name` varchar(128) DEFAULT NULL COMMENT '订单名称', - `product_id` bigint DEFAULT NULL COMMENT '购买产品id', - `buy_num` int DEFAULT NULL COMMENT '购买数量', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='订单表'; - -/*Data for the table `order_info_2` */ - -/*Table structure for table `undo_log` */ - -DROP TABLE IF EXISTS `undo_log`; - -CREATE TABLE `undo_log` -( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'increment id', - `branch_id` bigint NOT NULL COMMENT 'branch transaction id', - `xid` varchar(100) NOT NULL COMMENT 'global transaction id', - `context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization', - `rollback_info` longblob NOT NULL COMMENT 'rollback info', - `log_status` int NOT NULL COMMENT '0:normal status,1:defense status', - `log_created` datetime NOT NULL COMMENT 'create datetime', - `log_modified` datetime NOT NULL COMMENT 'modify datetime', - PRIMARY KEY (`id`), - UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) -) ENGINE=InnoDB AUTO_INCREMENT=406 DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table'; - -/*Data for the table `undo_log` */ - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_order_1.sql b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_order_1.sql deleted file mode 100644 index 1cbb66a5e..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_order_1.sql +++ /dev/null @@ -1,101 +0,0 @@ -/* -SQLyog Ultimate v13.1.1 (64 bit) -MySQL - 8.0.22 : Database - seata_order_1 -********************************************************************* -*/ - -/*!40101 SET NAMES utf8 */; - -/*!40101 SET SQL_MODE=''*/; - -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -CREATE -DATABASE /*!32312 IF NOT EXISTS*/`seata_order_1` /*!40100 DEFAULT CHARACTER SET utf8 */ /*!80016 DEFAULT ENCRYPTION='N' */; - -USE -`seata_order_1`; - -/*Table structure for table `order_info_0` */ - -DROP TABLE IF EXISTS `order_info_0`; - -CREATE TABLE `order_info_0` -( - `id` bigint NOT NULL COMMENT '订单id,采用分布式id', - `order_name` varchar(128) DEFAULT NULL COMMENT '订单名称', - `product_id` bigint DEFAULT NULL COMMENT '购买产品id', - `buy_num` int DEFAULT NULL COMMENT '购买数量', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='订单表'; - -/*Data for the table `order_info_0` */ - -insert into `order_info_0`(`id`, `order_name`, `product_id`, `buy_num`, `create_time`, `update_time`) -values (1387382592208240641, '测试数据', NULL, 2, '2021-04-28 20:26:00', '2021-04-28 20:26:00'); - -/*Table structure for table `order_info_1` */ - -DROP TABLE IF EXISTS `order_info_1`; - -CREATE TABLE `order_info_1` -( - `id` bigint NOT NULL COMMENT '订单id,采用分布式id', - `order_name` varchar(128) DEFAULT NULL COMMENT '订单名称', - `product_id` bigint DEFAULT NULL COMMENT '购买产品id', - `buy_num` int DEFAULT NULL COMMENT '购买数量', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='订单表'; - -/*Data for the table `order_info_1` */ - -/*Table structure for table `order_info_2` */ - -DROP TABLE IF EXISTS `order_info_2`; - -CREATE TABLE `order_info_2` -( - `id` bigint NOT NULL COMMENT '订单id,采用分布式id', - `order_name` varchar(128) DEFAULT NULL COMMENT '订单名称', - `product_id` bigint DEFAULT NULL COMMENT '购买产品id', - `buy_num` int DEFAULT NULL COMMENT '购买数量', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='订单表'; - -/*Data for the table `order_info_2` */ - -insert into `order_info_2`(`id`, `order_name`, `product_id`, `buy_num`, `create_time`, `update_time`) -values (1387382407474315265, '测试数据', NULL, 2, '2021-04-28 20:25:17', '2021-04-28 20:25:17'); - -/*Table structure for table `undo_log` */ - -DROP TABLE IF EXISTS `undo_log`; - -CREATE TABLE `undo_log` -( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'increment id', - `branch_id` bigint NOT NULL COMMENT 'branch transaction id', - `xid` varchar(100) NOT NULL COMMENT 'global transaction id', - `context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization', - `rollback_info` longblob NOT NULL COMMENT 'rollback info', - `log_status` int NOT NULL COMMENT '0:normal status,1:defense status', - `log_created` datetime NOT NULL COMMENT 'create datetime', - `log_modified` datetime NOT NULL COMMENT 'modify datetime', - PRIMARY KEY (`id`), - UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) -) ENGINE=InnoDB AUTO_INCREMENT=406 DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table'; - -/*Data for the table `undo_log` */ - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; diff --git a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_product.sql b/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_product.sql deleted file mode 100644 index 024fa425a..000000000 --- a/springcloud-seata-sharding-jdbc-mybatis-plus-samples/sql-and-seataconfig/seata_product.sql +++ /dev/null @@ -1,63 +0,0 @@ -/* -SQLyog Ultimate v13.1.1 (64 bit) -MySQL - 8.0.22 : Database - seata_product -********************************************************************* -*/ - -/*!40101 SET NAMES utf8 */; - -/*!40101 SET SQL_MODE=''*/; - -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -CREATE -DATABASE /*!32312 IF NOT EXISTS*/`seata_product` /*!40100 DEFAULT CHARACTER SET utf8 */ /*!80016 DEFAULT ENCRYPTION='N' */; - -USE -`seata_product`; - -/*Table structure for table `product_info` */ - -DROP TABLE IF EXISTS `product_info`; - -CREATE TABLE `product_info` -( - `id` bigint NOT NULL COMMENT '产品id,采用分布式id', - `product_name` varchar(128) DEFAULT NULL COMMENT '产品名称', - `stock` int DEFAULT NULL COMMENT '库存量', - `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='产品表'; - -/*Data for the table `product_info` */ - -insert into `product_info`(`id`, `product_name`, `stock`, `create_time`, `update_time`) -values (1, '蓝牙耳机', 9998, '2021-04-28 19:25:39', '2021-04-28 20:26:30'); - -/*Table structure for table `undo_log` */ - -DROP TABLE IF EXISTS `undo_log`; - -CREATE TABLE `undo_log` -( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'increment id', - `branch_id` bigint NOT NULL COMMENT 'branch transaction id', - `xid` varchar(100) NOT NULL COMMENT 'global transaction id', - `context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization', - `rollback_info` longblob NOT NULL COMMENT 'rollback info', - `log_status` int NOT NULL COMMENT '0:normal status,1:defense status', - `log_created` datetime NOT NULL COMMENT 'create datetime', - `log_modified` datetime NOT NULL COMMENT 'modify datetime', - PRIMARY KEY (`id`), - UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) -) ENGINE=InnoDB AUTO_INCREMENT=407 DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table'; - -/*Data for the table `undo_log` */ - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; diff --git a/tcc-sample/pom.xml b/tcc-sample/pom.xml new file mode 100644 index 000000000..982d041ed --- /dev/null +++ b/tcc-sample/pom.xml @@ -0,0 +1,19 @@ + + + + seata-samples + io.seata + 1.1.0 + + 4.0.0 + + tcc-sample + + + 8 + 8 + + + \ No newline at end of file diff --git a/xa-sample/pom.xml b/xa-sample/pom.xml new file mode 100644 index 000000000..0e3fc6626 --- /dev/null +++ b/xa-sample/pom.xml @@ -0,0 +1,19 @@ + + + + seata-samples + io.seata + 1.1.0 + + 4.0.0 + + xa-sample + + + 8 + 8 + + + \ No newline at end of file