1. Define a service
Https://www.consul.io/docs/agent/services.html
This method is the most common way to provide services in a service registration.
About the service definition: properties of the service we will each appear in the back of a summary one, and finally do a summary.
2. Service Registration
2.1. Create the folder where the service files are stored
Description
- . D Suffix: Indicates the directory where a series of configuration files are stored (directory)
2.2. Create a service and write to a file in the above folder
Description
- A service we will configure as JSON format : For example, the form between the single quotation marks above
- A service is written in a JSON file
Attention:
- If the above folder does not have permission to operate, change the folder permissions first,
3. Service Enquiry
Start the consul process first.
Toggle Screen--
Description
- Start the service according to the files in the directory that-config-dir specifies according to the service registration.
Two ways of querying:DNS and HTTP
3.1. DNS:
Name of the service visited:
- tag. servicename. Service.consul tag and servicename are all configured when the service is created
- The DNS access port is 8600
3.2. HTTP:
Description
- Access path: host:port/ version number /catalog/service/service name
- Address: Used to specify the IP address of a specific service, by default, the agent used by the service.
4, multiple service registration situation
4.1, each service registered to a file
Assuming that a Secondservice service is now created, I will write the service to the Secondservice.json file as follows:
Use HTTP to access:
Description: Access According to the name of the service.
4.2, multiple services written in the same JSON file
Description
- In services rather than service (the single-file service on the top is placed in services)
- Multiple services placed inside an array
Use HTTP to access:
Description: Access According to the name of the service.
Note: In the actual development, the number of micro-services,
If each file is placed in a file, the file will be very many, not good!
If all microservices are placed in a file, the file is too large and not good!
Therefore, they need to be combined . For example, suppose you have 100 microservices, put in 10 JSON files, and each JSON file holds 10 services.
Article reference from: https://www.consul.io/intro/getting-started/services.html
Chapter III Consul Service registration and service enquiry