Spring Cloud (2): Eureka サーバー登録センター

1. エウレカとは

Eureka は Netflix のオープンソース REST ベースのサービス ガバナンス ソリューションであり、Spring Cloud は Eureka を統合してサービス ガバナンスとサービス ディスカバリ機能を提供し、Spring Boot 上に構築されたマイクロサービス アプリケーションと簡単に統合できます。

2. 春雲エウレカの構成

  1. エウレカサーバー、レジストリ

  2. Eureka Client、登録されるすべてのマイクロサービスは Eureka Client 経由で Eureka Server に接続し、登録を完了します

3、実戦!登録センターを迅速に構築する

  1. 親プロジェクトを作成します。pom.xml 構成は次のとおりです
<parent>
  	<groupId>org.springframework.boot</groupId>
  	<artifactId>spring-boot-starter-parent</artifactId>
  	<version>2.0.7.RELEASE</version>
  </parent>
  
  <dependencies>
  	<dependency>
  		<groupId>org.springframework.boot</groupId>
  		<artifactId>spring-boot-starter-web</artifactId>
  	</dependency>
  </dependencies>
  
  <dependencyManagement>
  	<dependencies>
  		<dependency>
  			<groupId>org.springframework.cloud</groupId>
  			<artifactId>spring-cloud-dependencies</artifactId>
  			<version>Finchley.SR2</version>
  			<type>pom</type>
  			<scope>import</scope>
  		</dependency>
  	</dependencies>
  </dependencyManagement>
  1. 親プロジェクトの下にサブプロジェクト モジュールを作成します。pom.xml の構成は次のとおりです。
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    <version>2.0.2.RELEASE</version>
</dependency>
  1. サブプロジェクトの下に application.yml を作成し、次のように Eureka 関連の設定を追加します。
server:
  # 当前Eureka Server服务端口
  port: 8761
eureka:
  client:
    # 是否将当前的Eureka Server服务作为客户端进行注册
    register-with-eureka: false
    # 是否获取其他Eureka Server服务的数据
    fetch-registry: false
    
    service-url:
      # 注册中心的访问地址
      defaultZone: http://localhost:8761/eureka/

プロパティの説明

* server.port:当前 Eureka Server 服务端口

* eureka.client.register-with-eureka:是否将当前的 Eureka Server 服务作为客户端进行注册

* eureka.client.fetch-registry:是否获取其他 Eureka Server 服务的数据

* eureka.client.service-url.defaultZone:注册中心的访问地址
  1. スタートアップクラスを作成する
package com.frr;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekServerApplication {
    
    
	public static void main(String[] args) throws Exception {
    
    
		SpringApplication.run(EurekServerApplication.class, args);
	}

}

ノート

* @SpringBootApplication:声明该类是 Spring Boot 服务的入口

* @EnableEurekaServer:声明该类是一个 Eureka Server 微服务,提供服务注册和服务发现的功能,即注册中心
  1. 正常に起動した後のインターフェース
    ここに画像の説明を挿入

4. まとめ

  1. 新しい親プロジェクトを作成し、pom ファイルにパブリック依存関係を追加します。

  2. 親プロジェクトにサブプロジェクト モジュールを作成し、必要なコンポーネントの依存関係をモジュールの pom ファイルに追加します。

  3. Spring Boot にポートと Eureka 関連の構成を追加する

  4. 最後に、スタートアップ クラスを作成し、スタートアップ クラスにアノテーションを追加して、現在のプロジェクトを Eureka Server にします。

ビジネスの観点から見ると、サービス センターに登録するサービスは、サービス プロバイダーとサービス コンシューマに分けることができます。では、サービス プロバイダーはどのようにして他のサービスにサービスを提供するのでしょうか? 次の記事 Spring Cloud (3) を楽しみにしましょう。 Eurekaクライアントサービスプロバイダー

開発エンジニアの一人も継続学習段階にあり、普段のちょっとした体験談を随時共有しています。私の書いた文章を読んでくれた方が、寄り道をせずに仕事や勉強の成功を祈っていただければ幸いです。
ブロガーの経験は限られていますが、欠点がある場合は、コミュニケーションを取り、一緒に改善することを歓迎します。同じ CSDN の皆さんと一緒に進歩していきたいと思っています。

著者 | スイートリトルスイートポテト
プロデュース | リトルスイートポテト

おすすめ

転載: blog.csdn.net/qq_36836370/article/details/130870018