In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to implement service registration consul in Spring Cloud. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
A brief introduction to consul
Consul has the following properties:
Service Discovery: consul registers services through http, and services and services interact with each other.
Service health monitoring
Key/value storage
Multiple data centers
Consul can run on machines such as mac windows linux.
II. Consul installation
Linux
$mkdir-p $GOPATH/src/github.com/hashicorp & & cd $! $git clone https://github.com/hashicorp/consul.git$ cd consul$ make bootstrap$ make bootstrap
Install under windows:
See how to install consul under windows
III. Construction project
Build a springboot project for consul-miya, and import the dependent pring-cloud-starter-consul-discovery, which depends on the file:
4.0.0 com.forezp consul-miya 0.0.1-SNAPSHOT jar consul-miya Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 1.5.2.RELEASE UTF-8 UTF-8 1.8 org.springframework.cloud spring-cloud-starter-consul -discovery org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-dependencies Dalston.RELEASE Pom import org.springframework.boot spring-boot-maven-plugin
Add the annotation @ EnableDiscoveryClient to its entry file ConsulMiyaApplication to enable service discovery:
@ SpringBootApplication@EnableDiscoveryClient@RestControllerpublic class ConsulMiyaApplication {@ RequestMapping ("/ hi") public String home () {return "hi, IBM miya";} public static void main (String [] args) {new SpringApplicationBuilder (ConsulMiyaApplication.class) .web (true) .run (args);}}
Specify the port of the consul service in its configuration file application.yml as 8500:
Spring: cloud: consul: host: localhost port: 8500 discovery: healthCheckPath: ${management.contextPath} / health healthCheckInterval: 15s instance-id: consul-miya application: name: consul-miyaserver: port: 8502
Start the project, visit localhost:8500, and you can find that consul-miya is registered.
Thank you for reading! This is the end of the article on "how to implement service registration consul in Spring Cloud". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.