ユーレカのSpringCloudサービスの登録と発見(A)

ユーレカの基本的なアーキテクチャ

春の雲は、(飼育係を比較してください)サービスの登録と発見を実装するために開発されたNetflixのユーレカモジュールをカプセル化します。

CSの設計アーキテクチャを使用してユーレカ。サービスレジストリでサーバーのサービス登録機能、などユーレカサーバー。

そして、他のマイクロサービスシステム、ユーレカサーバーに接続して、ハートビート接続を維持するために、クライアントを使用しています。このようなシステムの保守要員は、サービスがユーレカサーバーで適切に機能している各マイクロシステムを監視することができます。SpringCloud(例えばZuulのような)他のモジュールのいくつかは、ユーレカサーバを介して他のマイクロサービスシステムに見られる、及び関連ロジックを実装することができます。

ユーレカの3つの役割の二つ

    

  • ユーレカServerサービスの登録と発見

  • サービスの消費者が検索しているので、サービスプロバイダサービスプロバイダは、ユーレカにサービスを登録します

  • ユーレカから登録されたサービスのリストを取得するために、サービス消費者サービスコンシューマ、それによって消費者サービス

3段階の建設

  • ユーレカ・サーバープロジェクトを作成します。

    • pom.xml


     
    <依存性> 
            <依存性> 
                <のgroupId> org.springframework.boot </のgroupId> 
                <たartifactId>ばねブートスタータウェブ</たartifactId> 
            </依存> 
            <依存性> 
                <のgroupId> org.springframework.cloud </のgroupId > 
                <たartifactId>ばねクラウドスタータのNetflix、ユーレカサーバ</たartifactId> 
            </依存> <依存性> 
                <のgroupId> org.springframework.boot </のgroupId> 
                <たartifactId>ばねブートスタータ試験< /たartifactId> 
                <スコープ>テスト</スコープ> 
            </依存> 
        </依存関係> <dependencyManagement> 
            <依存性>
            
         
                <依存> 
                    <のgroupId> org.springframework.cloud </のgroupId> 
                    <たartifactId>ばねクラウド依存性</たartifactId> 
                    <バージョン> $ {ばねcloud.version} </バージョン> 
                    <タイプ> POM </タイプ> 
                    <スコープ> インポート </スコープ> 
                </依存関係> 
            </依存関係> 
        </ dependencyManagement> <構築> 
            <プラグイン> 
                <プラグイン> 
                    <groupIdを> org.springframework.boot </ groupIdを> 
                    <たartifactId>春・ブート達人-plugin </たartifactId>
                </プラグイン> 
            </プラグイン> 
        </構築>
        

     

    • YML

      サーバー:
        ポート: 8761 
      ユーレカ:
        インスタンス:
          ホスト名:localhostの
        クライアント:
          registerWithEureka:
          fetchRegistry:
          のserviceURL:
            defaultZoneます。http:// $ {eureka.instance.hostname}:$ {はserver.port} /ユーリカ/

       

    • スタートアップクラス

      @SpringBootApplication 
      @EnableEurekaServer 
      パブリック クラスEurekaServerApplication { 
          公共 静的 ボイドメイン(文字列[]引数){ 
              SpringApplication.run(EurekaServerApplication。クラス、引数)。
          } 
      }

       

    • 結果を開始

  • プロデューサー・サービスを作成します。

    • pom.xml

      1    <依存性>
       2          <依存性>
       3              <のgroupId> org.springframework.boot </ groupIdを>
       4              <たartifactId>ばねブートスタータアクチュエータ</たartifactId>
       5          </依存>
       6          <依存性>
       7              <のgroupId> ORG .springframework.boot </ groupIdを>
       8              <たartifactId>ばねブートスタータウェブ</たartifactId>
       9          </依存>
       10          <依存性>
       11              <のgroupId> org.springframework.cloud </ groupIdを>
       12              <たartifactId>
      春・クラウド・スターター・ネットフリックス - ユーレカ・クライアント</たartifactId>13          </依存>
       14  15          <依存性>
       16              <のgroupId> org.springframework.boot </ groupIdを>
       17              <たartifactId>ばねブートスタータ試験</たartifactId>
       18              <スコープ>テスト</範囲>
       19          < /依存>
       20      </依存関係>
       21 22      <dependencyManagement>
       23          <依存性>
       24              <依存性>
       25                  <のgroupId> org.springframework.cloud </ groupIdを>
       26                  <
      たartifactId>春・クラウドの依存関係</たartifactId> 27                  <バージョン> $ {ばねcloud.version} </バージョン>
       28                  <タイプ> POM </タイプ>
       29                  <スコープ> インポート </範囲>
       30              </依存>
       31          </依存関係>
       32      </ dependencyManagement>
       33      <! -微服务情報内容详细信息- >
       34      <構築>
       35          <finalName> microservicecloud </ finalName>
       36          <資源>
       37              <資源>
       38                  <ディレクトリ>のsrc /メイン/リソース</ディレクトリ>
      39                  <フィルタ> </フィルタリング>
       40              </リソース>
       41          </リソース>
       42          <プラグイン>
       43              <プラグイン>
       44                  <のgroupId> org.apache.maven.plugins </ groupIdを>
       45                  <たartifactId>達人資源-プラグイン</たartifactId>
       46                  <設定>
       47                      <区切り文字>
       48                          <区切るよう> $ </境界を定める>
       49                      </区切り文字>
       50                  </ configuration>の
       51              </プラグイン>
      52          </プラグイン>
       53     </構築>
    • YML

      ユーレカ:
        クライアント:
          serviceURLの:
            defaultzone:HTTP:// localhostを:8761 /ユーレカ/ 
        インスタンス:          
          インスタンスは -id:製品- service8080#ホスト名:サービスの名前を変更する
          ことを好む -ip-アドレスを:trueに   #アクセス・パスのIPアドレスを表示するには、
      サーバーを:
        ポート: 8080 
      春:
        アプリケーション:
          名前:製品 - サービス
      #マイクロコンテンツサービス情報の詳細
      情報:
        app.name:製品 - SERVIC 
        company.name:www.topcheer.com

       

    • スタートアップクラス

      @SpringBootApplication
       パブリック クラスProducerServiceApplication { 
          公共 静的 ボイドメイン(文字列[]引数){ 
              SpringApplication.run(ProducerServiceApplication クラス、引数)。
          } 
      }
    • 結果:

                    

おすすめ

転載: www.cnblogs.com/dalianpai/p/11687145.html