Spring Boot + spring Cloud microservice implementation tutorial 2, springcloud

Source: Internet
Author: User

Spring Boot + spring Cloud microservice implementation tutorial 2, springcloud

The previous article has explained the simple steps for creating a maven project in spring boot. I believe that many people familiar with Maven + Eclipse are familiar with the development of common tools. This article mainly explains how to create a maven project, build the framework of spring boot + spring cloud to implement microservices, but before that, we need to first understand the function group and some frequently mentioned concepts of spring boot + spring cloud service framework.

1: Registration Center. spring boot + spring cloud uses Eureka as the Service Registration Center. zookeeper is also often used as the service registration center in early dubbo + zookeeper microservices.

2: service governance and service scheduling

3: Client Server Load balancer (including three common load balancing policies)

4: Fault Tolerance protection for remote service scheduling, that is, the fuse (Circuit Breaking Mechanism) mentioned in circuit design)

5: declarative remote scheduling of spring cloud

6: Service Routing and service forwarding

I personally feel that as a microservice built by spring boot + spring cloud, I am familiar with the above concepts, and then look at the essence of framework design with the concepts of the framework, both the overall and general aspects are clear.

Well, let's talk a little bit about creating spring boot + spring cloud microservices.

(Declaration: JDK 1.8, spring boot: 1.5.10.RELEASE, spring cloud: Edgware. SR2)

I. Create a Service Registration Center

File ----> new -----> other

For example, we select Eureka Discov and Eure Server modules. After the building is complete, let's take a look at the directory structure of the built project and the dependency between maven components used by the project.

Note: Why do we need to say a few more words here to explain why, because maven is used as the dependency between jar packages, there is often a conflict between the versions of the Xiang jar package, there is a version conflict between spring boot and spring cloud. However, we chose the most compatible version for Eclipse when selecting the spring Boot version. Otherwise, it will be very painful to step on the trap. All the code 66 running in other projects will become awesome to you.

This is the project result diagram. We have introduced it in the previous article. Here we will not introduce it much. Let's look at the code of the Registration Center, as shown in the blue section below, we need to add the Registration Center annotation. @ EnableEurekaServer

 

 

Let's take a look at the maven jar package dependency.

The following is the configuration file of application. properties.

For the convenience of building copy and paste, the following code is directly pasted here,

# Set the registry port
Server. port = 8000
# Name of the injected Service Application
Spring. application. name = registry-center
# Security Authentication
Security. basic. enabled = true
Security. user. name = top-registry-center
Security. user. password = 123456
Security. user. role = admin
Eureka. instance. hostname = peer1
# Close the Registration Center and register yourself to the Local Service
Eureka. client. register-with-eureka = false
Eureka. client. fetch-registry = false
# Registration center console address
# Eureka. client. serviceUrl. defaultZone = http: // 114.55.73.147: 18020/eureka/
# Irrelevant Registration Center configuration information, marking Registration Center Health Information
Eureka. instance. statusPageUrlPath =/info
Eureka. instance. healthCheckUrlPath =/health

Next, start the main method.

RegistryCenterApplication, as shown in the following figure. We find that the spring Boot App is missing.

Then open the browser and enter local host: 8000.

 

Finally, let's take a look at another access path: peer1: 8000,

Here, you need to configure the host Name of windows as the ing.

As follows:

We can see that 127.0.0.1 localhost maps the address of our local machine.

Here we will add peer1's registration center Address Configuration

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.