亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Spring boot2X負(fù)載均衡和反向代理實(shí)現(xiàn)過程解析

 更新時(shí)間:2019年12月02日 09:57:47   作者:慕塵  
這篇文章主要介紹了Spring boot2X負(fù)載均衡和反向代理實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了Spring boot2X負(fù)載均衡和反向代理實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

zuul 是netflix開源的一個(gè)API Gateway 服務(wù)器

所有從設(shè)備或網(wǎng)站來的請求都會(huì)經(jīng)過Zuul到達(dá)后端的Netflix應(yīng)用程序。

作為一個(gè)邊界性質(zhì)的應(yīng)用程序,Zuul提供了動(dòng)態(tài)路由、監(jiān)控、彈性負(fù)載和安全功能。

實(shí)現(xiàn)反向代理

1.服務(wù)注冊發(fā)現(xiàn)中心Consul

啟動(dòng)

consul agent -dev

2.服務(wù)端

provider和provider1

spring boot 版本 2.2.1.RELEASE

(1)添加依賴

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

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

  </dependencies>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

(2)配置

server.port=8010

spring.application.name=service-provider
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.health-check-path=/actuator/health
spring.cloud.consul.discovery.service-name=${spring.application.name}
spring.cloud.consul.discovery.heartbeat.enabled=true

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

(3)測試方法

package com.xyz.provider.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class demoController {
  @RequestMapping("/hello")
  public String Hello(){
    return "hello,provider";
  }
}

(4)啟動(dòng)類

package com.xyz.provider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class ProviderApplication {
  public static void main(String[] args) {
    SpringApplication.run(ProviderApplication.class, args);
  }
}

provide1的

server.port=8011

測試方法

package com.xyz.provider1.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class demoController {
  @RequestMapping("/hello")
  public String Hello(){
    return "hello,another provider";
  }

}

3.網(wǎng)關(guān)

  • zuul
  • Spring boot版本 2.1.8.RELEASE

上面用的Spring boot版本為 2.2.1.RELEASE

但是啟動(dòng)時(shí)遇到了報(bào)錯(cuò),因此改成了這個(gè)版本

(1)添加依賴

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
    </dependency>

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

  </dependencies>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

(2)添加配置

server.port=8090

spring.application.name=service-zuul
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.service-name=${spring.application.name}
spring.cloud.consul.discovery.instance-id=${spring.application.name}:${server.port}
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

zuul.routes.api.path=/api/**
zuul.routes.api.serviceId=service-provider

(3)啟動(dòng)類

package com.xyz.zuul;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@EnableZuulProxy
@SpringBootApplication
public class ZuulApplication {

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

啟動(dòng)Consul

啟動(dòng)provider、provider1

啟動(dòng) zuul

訪問http://127.0.0.1:8090/api/hello

結(jié)果輸出:

  hello,provider和hello,another provider

結(jié)果交替出現(xiàn)的,負(fù)載均衡器采用的是輪詢的方式

示例 https://gitee.com/babybeibeili/zuul_consul.git

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • springboot 單文件上傳的實(shí)現(xiàn)步驟

    springboot 單文件上傳的實(shí)現(xiàn)步驟

    這篇文章主要介紹了springboot實(shí)現(xiàn)單文件上傳的方法,幫助大家更好的理解和使用springboot框架,感興趣的朋友可以了解下
    2021-02-02
  • 一個(gè)JAVA小項(xiàng)目--Web應(yīng)用自動(dòng)生成Word

    一個(gè)JAVA小項(xiàng)目--Web應(yīng)用自動(dòng)生成Word

    前段時(shí)間接到一個(gè)Web應(yīng)用自動(dòng)生成Word的需求,現(xiàn)整理了下一些關(guān)鍵步驟拿來分享一下。
    2014-05-05
  • mybatis-plus返回查詢總記錄數(shù)方式

    mybatis-plus返回查詢總記錄數(shù)方式

    這篇文章主要介紹了mybatis-plus返回查詢總記錄數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • springBoot 插件工具熱部署 Devtools的步驟詳解

    springBoot 插件工具熱部署 Devtools的步驟詳解

    這篇文章主要介紹了springBoot 插件工具 熱部署 Devtools,本文分步驟給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Java編寫時(shí)間工具類ZTDateTimeUtil的示例代碼

    Java編寫時(shí)間工具類ZTDateTimeUtil的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何利用Java編寫時(shí)間工具類ZTDateTimeUtil,文中的示例代碼講解詳細(xì),有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-11-11
  • 詳解spring mvc對(duì)異步請求的處理

    詳解spring mvc對(duì)異步請求的處理

    spring mvc3.2及以上版本增加了對(duì)請求的異步處理,是在servlet3的基礎(chǔ)上進(jìn)行封裝的,有興趣的可以了解一下。
    2017-01-01
  • 使用MultipartFile實(shí)現(xiàn)文件上傳功能

    使用MultipartFile實(shí)現(xiàn)文件上傳功能

    這篇文章主要介紹了使用MultipartFile實(shí)現(xiàn)文件上傳功能,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • Java AQS中閉鎖CountDownLatch的使用

    Java AQS中閉鎖CountDownLatch的使用

    CountDownLatch 是一個(gè)同步工具類,用來協(xié)調(diào)多個(gè)線程之間的同步,它能夠使一個(gè)線程在等待另外一些線程完成各自工作之后,再繼續(xù)執(zhí)行。被將利用CountDownLatch實(shí)現(xiàn)網(wǎng)絡(luò)同步請求,異步同時(shí)獲取商品信息組裝,感興趣的可以了解一下
    2023-02-02
  • 詳細(xì)解讀java同步之synchronized解析

    詳細(xì)解讀java同步之synchronized解析

    synchronized關(guān)鍵字是Java里面最基本的同步手段,下面我們來一起學(xué)習(xí)一下
    2019-05-05
  • springboot中Getmapping獲取參數(shù)的實(shí)現(xiàn)方式

    springboot中Getmapping獲取參數(shù)的實(shí)現(xiàn)方式

    這篇文章主要介紹了springboot中Getmapping獲取參數(shù)的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05

最新評(píng)論