Seata will use Nacos as the registration and configuration center for SpringCloud Alibaba. A series of articles, welcome to continue to pay attention.

In the previous article, we used Seata’s file configuration to implement distributed transactions. Since this series of articles uses Springcloud Alibaba buckets and Seata happens to support Naocs, we will definitely choose Nacos as the Seata registry configuration center. In this article, we will integrate Seata into Nacos step by step. Let’s try it with me

Configuration to adjust

The server configuration is modified

The server modifies the Seataconfregistry. Conf file to make Seata use Nacos as the registry configuration center. The modified file is as follows:

Registry {# file, nacos, eureka, redis, Zk, Consul, ETCD3, SOFA type = "nacos" nacos {serverAddr = "192.168.136.1313:8848" Namespace = "" cluster = "default"}} config {# file, nacos, Apollo, ZK, consul, etCD3 type = "nacos" nacos {serverAddr = "192.168.136.130:8848" Namespace = ""}}Copy the code

Push the Seata configuration to Nacos

Modify the seataconfnacos-config. TXT file as follows:

  • Modify the tx – service – group



    As shown in the figure above, the modified format isservice.vgroup_mapping.${spring.alibaba.seata.tx-service-group}=defaultCombined with our system services, the modified results are as follows:
service.vgroup_mapping.account-service-seata=default
service.vgroup_mapping.product-service-seata=default
service.vgroup_mapping.order-service-seata=defaultCopy the code

  • Enable automatic database agent
support.spring.datasource.autoproxy=trueCopy the code

  • Push the configuration to Nacos

    Here we areseataconfOpen the Git terminal and runSh nacos - config. Sh 192.168.136.130



    If the following log is displayed on the Git terminal, the push is successful
init nacos config finished, please start seata-server.Copy the code

  • Log in to the NACOS console to verify the configuration



    You can see the 63 seATa-related configurations above.

    For fun: this configuration looks so messy, look forward to this piece can be optimized in the future!

Seata Server storage mode (store.mode) available file, DB (this series uses file mode, To use db mode, you can refer to http://seata.io/zh-cn/docs/ops/deploy-guide-beginner.html). The differences between the two modes are as follows:

* File mode is the single-machine mode, the global transaction session information in memory read and write and persist the local file root.data, high performance;

* DB mode is high availability mode, global transaction session information is shared through DB, corresponding performance is poor.

Client Modification

In the last article we worked on the service projectresourceThere are two files in the folderfile.conf.registry.confThis time we just need to delete file.conf and copy the registry.

test

Test as follows:

  • Start the Seata – Server



    Log in to the NACOS console and you can see that Seata is registered with NACOS
  • Start microservices



    Service registration is visible on the Seata console
  • Business test

    In normal cases, the following logs are displayed



    You will see this log if you need to roll back an exception

— Well, friends, this issue of “SpringCloud Alibaba micro-service actual combat 8 – Seata integration Nacos” is all over now, let’s see you next!

one more thing! If you find this article useful, please “forward”, please “watch”. Celebrities don’t talk dirty. I love it!

one more thing again! Let me ask for another wave of attention before goodbye, please scan the qr code below to contact me

series

  • SpringCloud Alibaba Micro service practice 7 – Distributed transactions
  • SpringCloud Alibaba Micro Service Practice 6 – Configuration isolation
  • SpringCloud Alibaba micro-service practice five – current limit fuse
  • SpringCloud Alibaba Micro service practice 4 – version management
  • SpringCloud Alibaba micro-service practice 3 – service invocation
  • SpringCloud Alibaba micro-service practice ii – service registration
  • SpringCloud Alibaba micro-service practice I – basic environment preparation

Please scan the code to follow the wechat public account or personal blog