Use Springcloud real-life Micro services

Source: Internet
Author: User
Tags config tostring xmlns
a Micro Service architecture Overview 1.1 Micro-service features and benefitsEach service can run independently in its own process a series of self-running microservices (Goods,order,pay,user,search ...) To build the whole system together. Each service is developed for independent business, a microservices focus on a particular feature, such as user management, and commodity management microservices microservices communicate through a few lightweight communication mechanisms, such as calling the technology stack through a restful API: A fully automated deployment mechanism with different development languages and data storage technologies to scale on demand: fine-grained horizontal scaling based on requirements and application scenarios 1.2 Micro-service challengesOperation and maintenance requirements higher distributed complexity interface adjustment cost is higher 1.3 Micro-service design principlesSingle duty principle service autonomy principle lightweight communication mechanism micro-service granularity 1.4 Micro-service development FrameworkSpringcloud: Many components are well-constructed distributed systems Dubbo/dubbox: Focus on Service governance Dropwizard: Focus on individual microservices development two Springcloud Overview and development environment 2.1 Springcloud Overview

Springcloud is a toolset based on Springboot to quickly build microservices systems with well-functioning lightweight microservices components such as service governance (Eureka), declarative rest invocation (feign), Client load Balancing (Ribbon), Service fault tolerance (HYSTRIX), service Gateway (Zuul), and service configuration (Spring Cloud Config), service Tracking (sleuth), and more.

Website Link: http://projects.spring.io/spring-cloud/
The current mainstream version is Springboot1.4.5.releae and SPRINGCLOUDCAMDEN.SR7,
The Maven POM configuration is as follows:

<parent> <groupId>org.springframework.boot</groupId> <artifactId> Spring-boot-starter-parent</artifactid> <version>1.4.5.RELEASE</version> </parent> < dependencymanagement> <dependencies> <dependency> <groupid>org.springframewor K.cloud</groupid> <artifactId>spring-cloud-dependencies</artifactId> <version
        >Camden.SR7</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency&gt
        ; <groupId></groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependen cy> <dependency> <groupId></groupId> <artifactid>spring-cloud-starter-eurek A</artifactid> </dependency> &Lt;/dependencies> 
2.2 Development Environment

Macos10.12+jdk8u131+intellij IDEA2017.1.4

tomcat8.5+maven3.3.9+git2.12+firefox54

Spring4.3.9.release+springboot1.4.5.release+springcloud CAMDEN.SR7 Three Engineering machine module Description 3.1 Project Description

The project first customizes the MAVEN parent project, which defines the following common components:

<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "htt P://www.w3.org/2001/xmlschema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 Http://maven.apach E.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <!--maven coordinates for custom projects--&lt
   ;groupid>com.ekeyfund.springcloud</groupid> <artifactId>springcloud-parent</artifactId> <version>2.0.0-SNAPSHOT</version> <packaging>pom</packaging> <!--based on Springboot 1.4.5.R elease--> <parent> <groupId>org.springframework.boot</groupId> <artifactId> Spring-boot-starter-parent</artifactid> <version>1.4.5.RELEASE</version> <relativepat h/> </parent> <!--definition Reference Class library version--<properties> &LT;PROJECT.BUILD.SOURCEENCODING&G T Utf-8</project.build.sourcEencoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <j
        Ava.version>1.8</java.version> <spring-cloud.version>Camden.SR7</spring-cloud.version> <springcloud-parent.version>2.0.0-SNAPSHOT</springcloud-parent.version> <druid.version>1.0.31 </druid.version> <jackson.version>2.8.8</jackson.version> <commons-lang3.version>3 .5</commons-lang3.version> <ehcache.version>3.1.4</ehcache.version>  
3.2 Module Description 

The module uses IntelliJ idea to automatically generate engineering structures with spring initializer, the main modules and descriptions are as follows:

Module Name Module Description Access Address
Springcloud-eureka-server Distributed Service Registration Center (single point) http://127.0.0.1:9999
Springcloud-eureka-server-ha Distributed service Registry (highly available version) http://127.0.0.1:9998 http://127.0.0.1:9997
Springcloud-provider-user-service User Service Provider Http://127.0.0.1:9996/list http://127.0.0.1:9995/list
Springcloud-consumer-h5 User Service caller, using the original resttemplate call Http://127.0.0.1:9991/user/get/4
Springcloud-consumer-h5-ribbon-hystrix User Service caller, using Ribbon for Client load Balancing Http://127.0.0.1:9994/springcloud-provider-user-service
Springcloud-consumer-h5-feign Feign declarative Service Caller Http://127.0.0.1:9993/list
Springcloud-gateway Gateway Service Http://127.0.0.1:9992/api-a/list
Springcloud-config-server Configuration Center Pending
four using Springboot to implement service providers

Maven module belongs to: Springcloud-provider-user-service
Springboot-based web and JPA modules a common way to implement restful APIs 4.1 entity

Mainly contains user,role,department three entities

Role.java

package com.ekeyfund.springcloud.entity;
Import javax.persistence.*;

Import java.io.Serializable; /** * Role Entity * * @author liuguanglei liuguanglei@ekeyfund.com * @create 2017-06-PM 2:36 */@Entity @Table (name = "Springboot_role") public class role implements serializable{@Id @GeneratedValue (strategy = Generationtype.ide

    ntity) @Column (name = "role_id") private Long ID;


    @Column (name = "Role_name") private String name;
    Public Long GetId () {return id;
    } public void SetId (Long id) {this.id = ID;
    } public String GetName () {return name;
    } public void SetName (String name) {this.name = name;
                } @Override Public String toString () {return new Org.apache.commons.lang3.builder.ToStringBuilder (this)
    . Append ("id", id). Append ("name", name). toString (); }
}

Department.java

Package com.ekeyfund.springcloud.entity;
Import Org.apache.commons.lang3.builder.ToStringBuilder;

Import Org.hibernate.annotations.CacheConcurrencyStrategy;
Import javax.persistence.*;

Import java.io.Serializable; /** * Department Entity * * @author liuguanglei liuguanglei@ekeyfund.com * @create 2017-06-PM 2:31 */@Entity @Table (n Ame = "Springboot_department") @org. Hibernate.annotations.Cache (Usage = Cacheconcurrencystrategy.nonstrict_read_ 
    WRITE) public class Department implements Serializable {@Id @GeneratedValue (strategy = generationtype.identity)


    @Column (name = "department_id") private Long ID;


    @Column (name = "Department_name") private String name;
    Public Long GetId () {return id;
    } public void SetId (Long id) {this.id = ID;
    } public String GetName () {return name;
    } public void SetName (String name) {this.name = name; } @Override Public String toString () {returN New Tostringbuilder (this). Append ("id", id). Append ("name", name). tostr
    ING ();

 }
}

User.java

Package com.ekeyfund.springcloud.entity;

Import com.fasterxml.jackson.annotation.JsonBackReference;
Import Org.apache.commons.lang3.builder.ToStringBuilder;
Import Org.springframework.format.annotation.DateTimeFormat;

Import javax.persistence.*;
Import java.io.Serializable;
Import java.util.Date;
Import java.util.List;

/**
 * User Entity
 *
 * @author liuguanglei liuguanglei@ekeyfund.com
 * @create 2017-06-PM 2:32 */
@Entity
@Table (name = "Springboot_user") Public
class user  implements serializable{

    @Id
    @Column (name = "user_id")
    @GeneratedValue (strategy = generationtype.identity)
    private Long ID;

    @Column (name = "user_name")
    private String name;


    @Column (name = "User_password")
    private String password;


    @Column (name = "User_create_date")
    @DateTimeF

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.