点来源 | Dromara分布式事务
感谢朋友们一路以来的支持,让大家久等了。在这一个版本中,我们团队重构了整个项目, 合理的划分功能模块,新增配置中心,调整底层存储结构,解决疑难bug,以及其他新功能的支持,也吸收了更多开源社区的优秀人才的加入。
Spring-Boot
, Spring-Namespace
快速与业务系统集成。Dubbo
, SpringCloud
,Montan
,sofa-rpc
等知名RPC框架。mysql
, oracle
, mongodb
, redis
, zookeeper
等方式。dubbo
框架不支持注解方式的使用(spring-boot-starter-dubbo)。hmotan
框架不支持注解方式的使用。spring-cloud
用户如果使用feign与hystrix整合hmily时候的线程切换问题。对于hmily用户来说,只需三个步骤,即可解决RPC服务调用之间的柔性事务
@Hmily
注解。用户依赖的方式没有更改,只需要将版本升级到2.1.0。下面举dubbo微服务列子
<dependency>
<groupId>org.dromara</groupId>
<artifactId>hmily-annotation</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>hmily-dubbo</artifactId>
<version>2.1.0</version>
</dependency>
or
<dependency>
<groupId>org.dromara</groupId>
<artifactId>hmily-spring-boot-starter-dubbo</artifactId>
<version>2.1.0</version>
</dependency>
在新版2.1.0中,新增了hmily-config模块,支持本地与注册中心模式。用户首先需要在项目resouce
文件下新建一个名称为hmily.yml
的文件。默认路径为项目的 resource
目录下,也可以使用 -Dhmily.conf
指定,也可以把配置放在 user.dir
目录下。优先级别 -Dhmily.conf
> user.dir
>resource
。文件格式如下(一部分,以下是配置成本地模式):
server:
configMode: local
appName: account-dubbo
# 如果server.configMode eq local 的时候才会读取到这里的配置信息.
config:
appName: account-dubbo
serializer: kryo
contextTransmittalMode: threadLocal
scheduledThreadMax: 16
scheduledRecoveryDelay: 60
scheduledCleanDelay: 60
scheduledPhyDeletedDelay: 600
scheduledInitDelay: 30
recoverDelayTime: 60
cleanDelayTime: 180
limit: 200
retryMax: 10
bufferSize: 8192
consumerThreads: 16
asyncRepository: true
autoSql: true
phyDeleted: true
storeDays: 3
repository: mysql
repository:
database:
driverClassName: com.mysql.jdbc.Driver
url : jdbc:mysql://127.0.0.1:3306/hmily?useUnicode=true&characterEncoding=utf8
username: root
password:
maxActive: 20
minIdle: 10
connectionTimeout: 30000
idleTimeout: 600000
maxLifetime: 1800000
hmily:
server:
configMode: nacos
appName: xxxxx
# 如果server.configMode eq local 的时候才会读取到这里的配置信息.
remote:
nacos:
server: 192.168.3.22:8848
dataId: hmily.properties
group: DEFAULT_GROUP
timeoutMs: 6000
fileExtension: yml
passive: true
nacos
配置中心上hmily:
server:
configMode: apollo
appName: xxxx
# 如果server.configMode eq local 的时候才会读取到这里的配置信息.
remote:
apollo:
appId: hmily-xxxxx
configService: http://192.168.3.22:8080
namespace: byin_hmily
secret:
fileExtension: yml
passive: true
env: dev
meta: http://192.168.3.22:8080
apollo
配置中心上还有其他的配置方式以及配置内容的详解,请参考:https://dromara.org/zh-cn/docs/hmily/config.html
在之前的版本中,rpc接口与实现都只需要添加 @Hmily
注解, 现在需要进行变更,在rpc接口方法上是添加 @Hmily
,用来标识这是一个hmily分布式事务的接口方法, 在接口的方法实现上则需要添加 @HmilyTCC
,然后指定 confirm
与 cancel
方法名称.
public interface HelloService {
@Hmily
void say(String hello);
}
public class HelloServiceImpl implements HelloService {
@HmilyTCC(confirmMethod = "sayConfrim", cancelMethod = "sayCancel")
public void say(String hello) {
System.out.println("hello world");
}
public void sayConfrim(String hello) {
System.out.println(" confirm hello world");
}
public void sayCancel(String hello) {
System.out.println(" cancel hello world");
}
}
FeignClient
中@FeignClient(value = "helle-service")
public interface HelloService {
@Hmily
@RequestMapping("/helle-service/sayHello")
void say(String hello);
}
@RestController
public class HelloController {
private final HelloService helloService ;
@Autowired
public AccountController(HelloService helloService) {
this.helloService= helloService;
}
@RequestMapping("/sayHello")
public void payment(String hello) {
return helloService.say(hello);
}
}
public interface HelloService {
void say(String hello);
}
public class HelloServiceImpl implements HelloService {
@HmilyTCC(confirmMethod = "sayConfrim", cancelMethod = "sayCancel")
public void say(String hello) {
System.out.println("hello world");
}
public void sayConfrim(String hello) {
System.out.println(" confirm hello world");
}
public void sayCancel(String hello) {
System.out.println(" cancel hello world");
}
}
在使用上,用户使用或者升级不用关心,框架会默认初始化好。
TAC
模式(try-auto-cancel)使用此模式,将大大简化框架的使用程度,开发者不需要关心confirm
以及cancel
方法的开发,对老系统的改造提供了更好的兼容性,不用担心额外的开发任务,一切就交给hmily吧。我们秉承和谐快乐,代码至上
的原则,如果你有想法,愿意和我们一起成长,一起贡献,快来加入我们吧!