Spring Cloud Consul

Source: Internet
Author: User
Tags lenovo

The Spring Cloud Consul project is a service governance implementation for consul. Consul is a distributed, highly available system that contains multiple components, but as a whole, a tool for providing service discovery and service configuration for our infrastructure in the microservices architecture. It contains the following features:

Service discovery
Health Check
Key/value Storage
Multi-Data center
Thanks to the implementation of the spring Cloud Consul project, we can easily register spring boot-based microservices applications on consul and implement service governance in the MicroServices architecture.

Based on the previously implemented Eureka-based example (eureka-client), how do we register previously implemented service providers on consul? The method is very simple and we only need to modify the dependency of Eureka in Pom.xml to the following dependencies:

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-consul-discovery</artifactId></dependency>

Then modify the Application.properites, add the configuration information consul need, such as: (The following configuration is the default value)

spring.cloud.consul.host=localhostspring.cloud.consul.port=8500

To this end, we have completed the conversion of Eureka-client to a service provider based on consul service governance. We have already mentioned that the service discovery interface Discoveryclient is a layer of abstraction from spring cloud for service governance, so we can mask the implementation details of Eureka and consul service governance, and our program does not need to make any changes. Simply introducing different service governance dependencies and configuring the associated configuration properties makes it easy to incorporate microservices into the various service governance frameworks of spring cloud.

Below you can try to get consul service providers up and running. Perhaps the reader will ask, is there no need to create a server like Eureka-server? Since the consul itself provides the service side, we do not need to create a service registry as previously implemented Eureka, which can be used directly by downloading the consul service-side program.

We can start the Consul development mode with the following command:

$consul agent -dev==> Starting Consul agent...==> Starting Consul agent RPC...==> Consul agent running!Version: ‘v0.7.2‘Node name: ‘Lenovo-zhaiyc‘Datacenter: ‘dc1‘Server: true (bootstrap: false)Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: falseAtlas: <disabled>

==> Log data would now stream in as it occurs:
2017/06/22 07:50:54 [INFO] raft:initial configuration (index=1): [{suffrage:voter id:127.0.0.1:8300 Address : 127.0.0.1:8300}]
2017/06/22 07:50:54 [INFO] raft:node at 127.0.0.1:8300 [Follower] entering Follower state (Leader: "")
2017/06/22 07:50:54 [INFO] SERF:EVENTMEMBERJOIN:LENOVO-ZHAIYC 127.0.0.1
2017/06/22 07:50:54 [INFO] consul:adding LAN server LENOVO-ZHAIYC (addr:tcp/127.0.0.1:8300) (DC:DC1)
2017/06/22 07:50:54 [INFO] SERF:EVENTMEMBERJOIN:LENOVO-ZHAIYC.DC1 127.0.0.1
2017/06/22 07:50:54 [INFO] consul:adding WAN server LENOVO-ZHAIYC.DC1 (addr:tcp/127.0.0.1:8300) (DC:DC1)
2017/06/22 07:51:01 [ERR] agent:failed to sync remote state:no cluster leader
2017/06/22 07:51:02 [WARN] raft:heartbeat timeout from "" reached, starting election
2017/06/22 07:51:02 [INFO] raft:node at 127.0.0.1:8300 [candidate] entering candidate state in term 2
2017/06/22 07:51:02 [DEBUG] raft:votes needed:1
2017/06/22 07:51:02 [DEBUG] Raft:vote granted from 127.0.0.1:8300 on term 2. Tally:1
2017/06/22 07:51:02 [INFO] Raft:election won. Tally:1
2017/06/22 07:51:02 [INFO] raft:node at 127.0.0.1:8300 [Leader] entering Leader state
2017/06/22 07:51:02 [INFO] consul:cluster leadership acquired
2017/06/22 07:51:02 [INFO] consul:new leader ELECTED:LENOVO-ZHAIYC
2017/06/22 07:51:02 [DEBUG] consul:reset tombstone GC to index 3
2017/06/22 07:51:02 [INFO] consul:member ' LENOVO-ZHAIYC ' joined, marking health alive
2017/06/22 07:51:02 [INFO] agent:synced service ' consul '
2017/06/22 07:51:02 [DEBUG] agent:node info in sync
After the consul server is started, we start the Consul service provider that was previously transformed. Consul, like Eureka, provides a simple UI interface to view the registration of services:

From now on, I will record the process and the essence of the recently developed Springcloud micro-service cloud architecture, and help more friends who are interested in developing the Spring cloud framework, hoping to help more good scholars. Let's explore how the Spring cloud architecture is built and how it can be used in enterprise projects.

Spring Cloud Consul

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.