全新架构的 Hmily 分布式事务框架 2.1.1发布( 二 )

如果你想将配置文件放在`Nacos`配置中心:

  • 第一步:
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
  • 第二步:将hmily的配置,放在 nacos配置中心上
如果你想将配置文件放在`Apollo`配置中心:
  • 第一步:
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
  • 第二步:将hmily的配置,放在 apollo配置中心上
还有其他的配置方式以及配置内容的详解,请参考:https://dromara.org/zh-cn/docs/hmily/config.html
注解方式的使用的变更
在之前的版本中,rpc接口与实现都只需要添加 @Hmily 注解, 现在需要进行变更,在rpc接口方法上是添加 @Hmily,用来标识这是一个hmily分布式事务的接口方法, 在接口的方法实现上则需要添加 @HmilyTCC,然后指定 confirm 与 cancel方法名称.
举例(dubbo中say方法需要参与分布式事务):
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");    }}举例(springcloud中say方法需要参与分布式事务):
  • spring-cloud服务调用方FeignClient中
@FeignClient(value = "helle-service")public interface HelloService {    @Hmily    @RequestMapping("/helle-service/sayHello")    void say(String hello);}
  • spring-cloud服务提供方
@RestControllerpublic 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");    }}


推荐阅读