bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

Springboot2X中怎么實現負載均衡和反向代理-創新互聯

Springboot2X中怎么實現負載均衡和反向代理,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

為金水等地區用戶提供了全套網頁設計制作服務,及金水網站建設行業解決方案。主營業務為成都做網站、網站建設、金水網站設計,以傳統方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業、用心的態度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

zuul 是netflix開源的一個API Gateway 服務器

所有從設備或網站來的請求都會經過Zuul到達后端的Netflix應用程序。

作為一個邊界性質的應用程序,Zuul提供了動態路由、監控、彈性負載和安全功能。

實現反向代理

1.服務注冊發現中心Consul

啟動

consul agent -dev

2.服務端

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=8010spring.application.name=service-providerspring.cloud.consul.host=localhostspring.cloud.consul.port=8500spring.cloud.consul.discovery.health-check-path=/actuator/healthspring.cloud.consul.discovery.service-name=${spring.application.name}spring.cloud.consul.discovery.heartbeat.enabled=truemanagement.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;@RestControllerpublic class demoController {  @RequestMapping("/hello")  public String Hello(){    return "hello,provider";  }}

(4)啟動類

package com.xyz.provider;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@EnableDiscoveryClient@SpringBootApplicationpublic 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;@RestControllerpublic class demoController {  @RequestMapping("/hello")  public String Hello(){    return "hello,another provider";  }}

3.網關

zuul  Spring boot版本 2.1.8.RELEASE

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

但是啟動時遇到了報錯,因此改成了這個版本

(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=8090spring.application.name=service-zuulspring.cloud.consul.host=localhostspring.cloud.consul.port=8500spring.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=alwayszuul.routes.api.path=/api/**zuul.routes.api.serviceId=service-provider

(3)啟動類

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@SpringBootApplicationpublic class ZuulApplication {  public static void main(String[] args) {    SpringApplication.run(ZuulApplication.class, args);  }}

啟動Consul

啟動provider、provider1

啟動 zuul

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

結果輸出:

hello,provider和hello,another provider

關于Springboot2X中怎么實現負載均衡和反向代理問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創新互聯行業資訊頻道了解更多相關知識。

名稱欄目:Springboot2X中怎么實現負載均衡和反向代理-創新互聯
網站地址:http://vcdvsql.cn/article14/pgpde.html

成都網站建設公司_創新互聯,為您提供面包屑導航定制開發網站導航營銷型網站建設企業網站制作網站改版

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

綿陽服務器托管