springcloud全家桶个人博客系统(四)路由网关zuul组件搭建

一、简介

zuul路由网关,是指用户访问服务时,先访问网关,由网关转发给消费者,这样的一个过程。在本文中,网关将会转发用户的请求到消费者。

二、pom文件

    <dependencies>
        <!-- zuul路由网关 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <!-- actuator监控 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- hystrix容错 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sustly</groupId>
            <artifactId>blog_api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</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>
        </dependency>
        <!-- 热部署插件 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>4.1.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

三、主配置类

@SpringBootApplication
@EnableZuulProxy
@EnableDiscoveryClient
@EnableEurekaClient
public class BlogZuul {
        public static void main(String[] args) {
            SpringApplication.run(BlogZuul.class, args);
        }
}

注意:@EnableDiscoveryClient 服务发现注解,一定要加

四、application.properties

server.port=9527

spring.application.name=blog_zuul


eureka.client.service-url.defaultZone=http://localhost:7001/eureka
eureka.instance.instance-id=blog_zuul
eureka.instance.prefer-ip-address=true


zuul.ignored-services=blog-consumer-feign
zuul.routes.consumer.service-id=blog-consumer-feign
zuul.routes.consumer.path=/blog/**

blog-consumer-feign.ribbon.ConnectTimeout=5000
blog-consumer-feign.ribbon.ReadTimeout=5000

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000

info.app.name=blog_zuul
info.company.name=www.sustly.xyz
info.build.artifactId=${project.artifactId}
info.build.version=${project.version}

五、博客系统GitHub地址

https://github.com/sustly/blog_vue_server

注意:master分支才是springcloud版本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值