SpringCloud(フィンチリー版)チュートリアル(VII):スルース

I.はじめに

スプリングクラウドスルース主な機能は、分散システム内のトラッキング・ソリューションを提供することであり、互換性のある支持zipkinあります。

リンク上のサービスやネットワークのタイムアウトに問題が界面の形成につながる場合は、外部被ばくのインターフェースをRESTを呼び出すことによって、ビジネス・サービスで割った、マイクロサービスアーキテクチャ上で、この共同のサービス・インターフェース機能を完了するのに何ヶ月もかかる場合があります呼び出しが失敗しました。事業の継続的な拡大に伴い、サービス間でお互いを呼び出すと、あなたは、サービスチェーンを表示する行くことができる方法に応じて、より複雑になります。

ケース3つのメインプロジェクトコンポーネント:ZipkinServer機能を使用してサーバーzipkin、その主な役割、通話データと表示を収集し、探偵、クライアント、クライアント・インフォ・インタフェースの外部被ばく、探偵・サーバー、外国人には、サーバーの情報を公開インタフェース;両方のサービスは、お互いを呼び出すことができます;とだけ呼ばれる、サーバー・zipkinは、呼び出しをトレース理由である、データを収集します。

第二に、プロジェクトをビルド

2.1 Zipkinを作成します 

春クラウドは、時間のFバージョンでは、あなたは自分のZipkinサーバーを構築し、唯一のjarファイルをダウンロードする必要があり、ダウンロードする必要はありません。

https://dl.bintray.com/openzipkin/maven/io/zipkin/java/zipkin-server/

実行コマンドをコマンドボックスを開きます。java -jar 

訪問を開始した後にします。http:// localhost:9411

2.2探偵・クライアントを作成します

導入依存ばねクラウドスタータzipkin POMその上、次のようにコードであるを開始します。

<?xml version = "1.0"エンコード= "UTF-8"?> 
<プロジェクトのxmlns = "http://maven.apache.org/POM/4.0.0"のxmlnsを:XSI = "のhttp://www.w3 .ORG / 2001 / XMLスキーマ・インスタンス」
         の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> 
    <親> 
        <のgroupId> org.springframework.boot </のgroupId> 
        <たartifactId>ばねブートスタータ親</たartifactId> 
        <バージョン> 2.1.7.RELEASE </バージョン> 
        <relativePath /> <! -ルックアップ親リポジトリから- > 
    </親> 

    <groupIdを> com.liu </ groupIdを>
    <たartifactId>探偵・クライアント</たartifactId> 
    <バージョン> 0.0.1-SNAPSHOT </バージョン>
    <名前>探偵・クライアント</名前> 
        <依存>
    <説明>デモプロジェクトのための春の起動</記述> 

    <プロパティ> 
        <のjava.version> 1.8 </java.version> 
        <スプリングcloud.version> Greenwich.SR2 </spring-cloud.version> 
    </プロパティ> 

    <依存関係> 
        <依存> 
            <groupIdを> org.springframework.boot </ groupIdを> 
            <たartifactId>春・ブート・スターター・ウェブ</たartifactId> 
        </依存関係> 

        <依存> 
            <groupIdを> org.springframework.cloud </ groupIdを> 
            <たartifactId>ばねクラウドスタータzipkin </たartifactId> 
        </依存>

            <groupIdを> org.springframework.boot </ groupIdを>
            <たartifactId>ばねブートスタータ試験</たartifactId> 
            <スコープ>テスト</スコープ> 
        </依存> 

    </依存関係> 

    <構築> 
        <プラグイン> 
            <プラグイン> 
                <のgroupId> org.springframework.boot </のgroupId > 
                <たartifactId>春・ブート・プラグインのmaven-</たartifactId> 
            </プラグイン> 
        、</プラグ> 
    </構築> 

</プロジェクト> 

ヘッド「spring.zipkin.base-URL」を配置することにより、その設定ファイルapplication.ymlのzipkinサーバーのアドレスで指定された指定:

サーバー:
  ポート: 8988 
春:
  アプリケーション:
    名前:探偵 - クライアント
  zipkin:
    ベース -urlます。http:// localhostを:9411

ばねクラウドスタータzipkin提供spring.zipkin.base-URLとそれに依存を導入することによって。

外部被ばくインタフェース:

パッケージcom.liu.sleuthclient。

輸入org.springframework.beans.factory.annotation.Autowired;
輸入org.springframework.boot.SpringApplication。
輸入org.springframework.boot.autoconfigure.SpringBootApplication。
輸入org.springframework.context.annotation.Bean。
輸入org.springframework.web.bind.annotation.RequestMapping。
輸入org.springframework.web.bind.annotation.RestController。
輸入org.springframework.web.client.RestTemplate。

@SpringBootApplication 
@RestController 
パブリック クラスSleuthClientApplication { 

    公共の 静的な 無効メイン(文字列[]引数){ 
        SpringApplication.run(SleuthClientApplication。クラス、引数)。
    } 

    @Autowired 
    プライベートRestTemplate restTemplateは、

    @Bean 
    公共RestTemplate getRestTemplate(){
         戻り 新しい)(RestTemplateします。
    } 

    @RequestMapping( "/ HI" パブリック文字列CALLHOME(){
         リターン "私はスルースクライアントです" 
    } 

    @RequestMapping( "/クライアント情報" パブリック文字列情報(){
         リターンrestTemplate.getForObject( "のhttp:// localhostを:8989 / HI"。、文字列クラス)。
    } 
}

2.3探偵・サーバーを作成します

痛み作成サービス-HI、同じ依存設定spring.zipkin.base-URLに導入します。

<?xml version = "1.0"エンコード= "UTF-8"?> 
<プロジェクトのxmlns = "http://maven.apache.org/POM/4.0.0"のxmlnsを:XSI = "のhttp://www.w3 .ORG / 2001 / XMLスキーマ・インスタンス」
         の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> 
    <親> 
        <のgroupId> org.springframework.boot </のgroupId> 
        <たartifactId>ばねブートスタータ親</たartifactId> 
        <バージョン> 2.1.7.RELEASE </バージョン> 
        <relativePath /> <! -ルックアップ親リポジトリから- > 
    </親> 

    <groupIdを> com.liu </ groupIdを>
    <たartifactId>探偵・サーバー</たartifactId> 
    <バージョン> 0.0.1-SNAPSHOT </バージョン>
    <名前>探偵・サーバー</名前> 
        <依存>
    <説明>デモプロジェクトのための春の起動</記述> 

    <プロパティ> 
        <のjava.version> 1.8 </java.version> 
        <スプリングcloud.version> Greenwich.SR2 </spring-cloud.version> 
    </プロパティ> 

    <依存関係> 
        <依存> 
            <groupIdを> org.springframework.boot </ groupIdを> 
            <たartifactId>春・ブート・スターター・ウェブ</たartifactId> 
        </依存関係> 
        <依存> 
            <groupIdを> org.springframework.cloud </ groupIdを> 
            <たartifactId>ばねクラウドスタータzipkin </たartifactId> 
        </依存>

            <groupIdを> org.springframework.boot </ groupIdを>
            <たartifactId>ばねブートスタータ試験</たartifactId> 
            <スコープ>テスト</スコープ> 
        </依存> 
    </依存関係> 

    <構築> 
        <プラグイン> 
            <プラグイン> 
                <のgroupId> org.springframework.boot </のgroupId > 
                <たartifactId>春・ブートのmaven-pluginの</たartifactId> 
            </プラグイン> 
        </プラグイン> 
    </構築> 

</プロジェクト>
サーバー:
  ポート: 8989 
春:
  アプリケーション:
    名前:探偵 - サーバー
  zipkin:
    ベース -urlます。http:// localhostを:9411

外部被ばくインタフェース:

 
パッケージcom.liu.sleuthserver。

輸入org.springframework.beans.factory.annotation.Autowired;
輸入org.springframework.boot.SpringApplication。
輸入org.springframework.boot.autoconfigure.SpringBootApplication。
輸入org.springframework.context.annotation.Bean。
輸入org.springframework.web.bind.annotation.RequestMapping。
輸入org.springframework.web.bind.annotation.RestController。
輸入org.springframework.web.client.RestTemplate。

@SpringBootApplication 
@RestController 
パブリック クラスSleuthServerApplication { 

    公共の 静的な 無効メイン(文字列[]引数){ 
        SpringApplication.run(SleuthServerApplication。クラス、引数)。
    } 

    @Autowired 
    プライベートRestTemplate restTemplateは、

    @RequestMapping(「/ HI」公共の文字列の自宅(){
         リターン「私は探偵・サーバーですよ!」
    } 

    (@RequestMapping "/サーバ情報" パブリック)文字列情報({
         戻り restTemplate.getForObject( "HTTP:// localhostを:8988 / HI"、ストリングクラス)。

     新しいRestTemplate(); 
    } 
}

2.4スタートプロジェクト

// localhostを:8988 /クライアント情報とのhttp:// localhostを:のhttpをご覧ください8989 /サーバー-infoがお互いのインターフェイスを呼び出し、インターフェイスを選択し、アクセスzipkinに依存しているサービスの私達の連鎖を見ることができます。

 

おすすめ

転載: www.cnblogs.com/liuyuan1227/p/11484515.html