springcloud(七,多个服务消费者配置,以及zuul网关案例)

Posted 笑~笑

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springcloud(七,多个服务消费者配置,以及zuul网关案例)相关的知识,希望对你有一定的参考价值。

   

     spring cloud (一、服务注册demo_eureka)

      spring cloud (二、服务注册安全demo_eureka)

      spring cloud (三、服务提供者demo_provider)

     spring cloud (四、服务消费者demo_consumer)

     springcloud(五,多个服务注册中心eureka)

      springcloud(六,多个服务提供者)

  多个服务消费者同上面的提供者和服务注册一样的哈,就是复制出来两个,把端口改一下即可

   这里就不做截图了

   直接开始zuul网关

   同样新建一个zuul项目,注册到服务注册中心

  

 

 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com</groupId>
    <artifactId>zuul</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>zuul</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

启动类

@EnableEurekaClient
@EnableZuulProxy
@SpringBootApplication
public class ZuulApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZuulApplication.class, args);
    }

}

配置

spring.application.name=zuul
ribbon.eureka.enabled=false 
feign.hystrix.enabled=true
server.port=8661

zuul.routes.user.path=/zuul01/**

zuul.routes.user.serviceId=consumer
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:3334/eureka/

启动以后

 

 访问http://localhost:8661/zuul01/test01

 

 会自动进行负载均衡

 

 

 

以上是关于springcloud(七,多个服务消费者配置,以及zuul网关案例)的主要内容,如果未能解决你的问题,请参考以下文章

SpringCloud系列七:Hystrix 熔断机制(Hystrix基本配置服务降级HystrixDashboard服务监控Turbine聚合监控)

SpringCloud之Ribbon

springcloud+eureka简单入门案例

微服务-SpringCloud学习系列: 抽象中间件SpringCloudStream

SpringCloud学习成长之路七 高可用配置中心

SpringCloud--alibliba--Nacos--上