春クラウドゲートウェイサービスをzuul

前の比較NetflixのZuul 1.0およびゲートウェイ。今日は紹介し、アプリケーションzuulを構築します

Zuulプロジェクトが作成され

クラウドゲートウェイzuulを作成するためのプロジェクト。プロジェクトは、以前に基づいて
輸入ポンポンファイル

 <parent>
        <artifactId>spring-cloud-alibaba-basis</artifactId>
        <groupId>com.xian.cloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cloud-gateway-zuul</artifactId>
    <name>网关服务zuul</name>

    <dependencies>
        <!-- 注册中心 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <!-- 配置中心 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-nacos-config</artifactId>
        </dependency>
        <!-- fengin 支持 -->
       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- zuul -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
    </dependencies>

起動クラスのGatewayZuulApplicationを作成します。

package com.xian.cloud;

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;
import org.springframework.cloud.openfeign.EnableFeignClients;

/**
 * <Description>
 *
 * @author [email protected]
 * @version 1.0
 * @createDate 2019/10/29 10:52
 */
@EnableZuulProxy
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class GatewayZuulApplication {

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

作成bootstrap.yml

``
スプリング:
プロファイル:
活性:DEVの
アプリケーション:
名:ゲートウェイzuulサーバ
クラウド:
ナコス:
設定:
サーバ-ADDR:47.99.209.72:8848
ファイル拡張子:YAML

Zuul:
ホスト:
接続先ホスト#の最大数は、デフォルト値200がある
:1000 MAX-全接続
各ホストの接続の#初期数、デフォルト値は20である
MAX-毎経路接続:200である
ルート:
ディスカバリーサーバー- :
パス:/サーバ/
サービスID:クラウド・ディスカバリー・サーバ・
クライアント共通:
パス:/クライアント/

サービスID:クラウド・ディスカバリー・クライアント
sensitiveHeaders:X - ABC、認証
#は、すべてのデフォルトルートHystrix分離モード(ExecutionIsolationStrategy)がSEMAPHOREです。これは好ましい分離モードである場合は、zuul.ribbonIsolationStrategyスレッドに変更することができます
リボン型分離の戦略:スレッド
#をこの属性は、すべてのサービス担当無視する*サービスの指定されたリストを無視するという意味
無視-サービス:「*」
、敏感#フィールドにありません私たちは、下流マイクロサービスに渡したいです。無敏感無視フィールドは空を設定します。すべての渡された下流のサービス
敏感-ヘッダ:ABC-X-
リボン:
ロード熱心:
#強制的にロードされたが、怠惰な負荷設定はできません。春は非常に遅い最初のリクエストになります
有効:trueに
`` `

パラメータ

  • ターゲットホストの接続zuul.host.max、全接続の最大数。
  • 各ホストの接続zuul.host.maxあたりのルート接続の初期数。

2つのパラメータが最適化されたzuulプロパティ値であり、あなたが適切な構成を持つようにしたい場合は、また、ビジネス条件に基づいてする必要があります

我々は、ビジネスサービスが設定されている当社のサービスのサービス消費者が提供するサービスであるため、両方のルーティング発見 - サーバー、クライアント共通の

  • パスは、パス要求マッチングルールであります
  • サービスIDは、当社のサービスの対応する値をspring.application.nameです。
  • SensitiveHeaders敏感フィールド、下流マイクロサービスに渡す必要はありません。無敏感無視フィールドは空を設定します。この分野のすべての渡された下流のサービスが提供されるか、または単一のグローバルサービス設定することができます。
  • リボン型分離戦略は、すべてのデフォルトルートHystrix分離モード(ExecutionIsolationStrategy)がSEMAPHOREあります。これは好ましい分離モードである場合は、zuul.ribbonIsolationStrategyスレッドに変更することができます
  • 無視-サービスは、すべてのマイクロサービス、マイクロサービス指定された唯一のルートを無視します。
  • 怠惰力にロードribbon.eager-load.enabled True Falseデフォルト
    • 真偽ログ印刷このログを印刷しません

      2019-10-29 23:47:11.377  INFO 61396 --- [           main] c.netflix.loadbalancer.BaseLoadBalancer  : Client: cloud-discovery-server instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=cloud-discovery-server,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
      2019-10-29 23:47:11.382  INFO 61396 --- [           main] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
      2019-10-29 23:47:11.450  INFO 61396 --- [           main] c.netflix.config.ChainedDynamicProperty  : Flipping property: cloud-discovery-server.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
      2019-10-29 23:47:11.452  INFO 61396 --- [           main] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client cloud-discovery-server initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=cloud-discovery-server,current list of Servers=[192.168.3.6:9012],Load balancer stats=Zone stats: {unknown=[Zone:unknown;  Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
      },Server stats: [[Server:192.168.3.6:9012;  Zone:UNKNOWN;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 08:00:00 CST 1970;  First connection made: Thu Jan 01 08:00:00 CST 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
      ]}ServerList:com.alibaba.cloud.nacos.ribbon.NacosServerList@33e4b9c4
      2019-10-29 23:47:11.576  INFO 61396 --- [           main] c.netflix.config.ChainedDynamicProperty  : Flipping property: cloud-discovery-client.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
      2019-10-29 23:47:11.577  INFO 61396 --- [           main] c.netflix.loadbalancer.BaseLoadBalancer  : Client: cloud-discovery-client instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=cloud-discovery-client,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
      2019-10-29 23:47:11.578  INFO 61396 --- [           main] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
      2019-10-29 23:47:11.639  INFO 61396 --- [           main] c.netflix.config.ChainedDynamicProperty  : Flipping property: cloud-discovery-client.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
      2019-10-29 23:47:11.640  INFO 61396 --- [           main] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client cloud-discovery-client initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=cloud-discovery-client,current list of Servers=[192.168.3.6:9011],Load balancer stats=Zone stats: {unknown=[Zone:unknown;  Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
      },Server stats: [[Server:192.168.3.6:9011;  Zone:UNKNOWN;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 08:00:00 CST 1970;  First connection made: Thu Jan 01 08:00:00 CST 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
      ]}ServerList:com.alibaba.cloud.nacos.ribbon.NacosServerList@256589a1

すべての3つのサービスが開始されます。サービスプロバイダやサービスの消費者はzuulサービス持た
// localhostを:9083 /コマンドカールを入力します。httpコンソールでのクライアント/クライアント/テスト
ファイル
我々はプリントを見たが、要求は私達の下流サービスでゲートウェイサービスに転送に成功しました。そしてリターン

  • リボン型分離戦略
  • 無視-サービス
  • sensitiveHeaders

以上のいくつかのパラメータだけでなく、迎撃zuulサービスをルーティングを使用することは、説明するために、次のいずれかになります。

どのようにあなたはこの懸念パブリック番号を共有することができますように。
ファイル

免責事項:この記事はブロガーオリジナル記事です、BY-SAの著作権契約、複製、元のソースのリンクと、この文を添付してくださいCC 4.0に従ってください。公共の二次元コード番号を記入してください再版

おすすめ

転載: www.cnblogs.com/cloudxlr/p/11762495.html