Consul is an important registry implementation in the Seata component.
This article is based on Seata 1.4.2 and registers Seata to Consul with file as the configuration center.
Consul version recommended is 1.8+. The following text uses Consul 1.11.2 as an example.
Before you register Seata to Consul, make sure that the Consul service is already running. If you are not familiar with the basic usage of Consul, you can refer to the Consul official documentation first.
If you just want to experience it quickly, you can also use the following docker command to start a Consul container and access the Consul console at http://localhost:8500.
docker run -d --name=consul -p 8500:8500 -p 8600:8600/udp consul:1.11.2 agent -dev -client=0.0.0.0 -ui
Integrating Consul registry into Seata is very simple, with a Server-side and a Client-side.
The Server-side only needs to configure the "registry".
The Client-side needs to add Maven dependencies and configure them.
Server-side configuration of registry
Download Seata 1.4.2 release and extract it.
Modify the corresponding configuration center in /conf/registry.conf, and refer to the rest of the configuration.
type = "consul"
# The cluster name registered to Consul, default is default
cluster = "default"
serverAddr = "127.0.0.1:8500"
aclToken = ""
Execute /bin/seata-server.bat (Windows) or /bin/seata-server.sh (Unix) to start Seata. The service will run on port 8091 locally.
Go to the Consul console to check if Seata is registered successfully.
Client-side adding Maven dependencies
Taking a SpringBoot project as an example, add the following to the project's pom.xml
<version>latest version (Seata version)</version>
Add the corresponding registry to application.yml, and refer to the rest of the configuration.
# Transaction group configuration, default name is my_test_tx_group in version 1.4.2, will be changed to default_tx_group in version 1.5
# For more information about transaction groups, please refer to http://seata.io/en/docs/user/txgroup/transaction-group.html
# Mapping between transaction group and cluster
After completing the client configuration, start the application and wait for a moment. When the following log appears, you can officially experience the Seata service.
register TM success. client version:1.4.2, server version:1.4.2,channel:[id: 0xa4675e28, L:/127.0.0.1:8238 - R:/127.0.0.1:8091]
register RM success. client version:1.4.2, server version:1.4.2,channel:[id: 0x408192d3, L:/127.0.0.1:8237 - R:/127.0.0.1:8091]
register success, cost 94 ms, version:1.4.2,role:RMROLE,channel:[id: 0x408192d3, L:/127.0.0.1:8237 - R:/127.0.0.1:8091]
register success, cost 94 ms, version:1.4.2,role:TMROLE,channel:[id: 0xa4675e28, L:/127.0.0.1:8238 - R:/127.0.0.1:8091]