本例将会运行两个服务器,两个服务提供者实例和一个服务调用者实例,通过服务调用者请求服务,实现集群部署并通过HttpClient的REST客户端访问服务调用者发布的服务看到负载均衡的效果。

  03 Eureka集群的搭建

  由于本例的开发环境只有一台电脑,操作系统为Windows,如果要构建集群,需要修改hosts文件,为其添加主机名的映射,修改C:\Windows\System32\drivers\etc\hosts文件,添加以下内容:

  127.0.0.1 slave1 slave2

2.构建服务器端

  新建一个maven项目first-cloud-server,项目的目录结构如下图

  03 Eureka集群的搭建

  引入相关依赖

  pom.xml代码清单

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <modelVersion>4.0.0</modelVersion>
 6 
 7     <groupId>com.triheart</groupId>
 8     <artifactId>first-cloud-server</artifactId>
 9     <version>1.0-SNAPSHOT</version>
10 
11     <dependencyManagement>
12         <dependencies>
13             <dependency>
14                 <groupId>org.springframework.cloud</groupId>
15                 <artifactId>spring-cloud-dependencies</artifactId>
16                 <version>Dalston.SR1</version>
17                 <type>pom</type>
18                 <scope>import</scope>
19             </dependency>
20         </dependencies>
21     </dependencyManagement>
22 
23     <dependencies>
24         <dependency>
25             <groupId>org.springframework.cloud</groupId>
26             <artifactId>spring-cloud-starter-eureka-server</artifactId>
27         </dependency>
28     </dependencies>
29 
30 </project>
View Code

相关文章:

  • 2021-09-21
  • 2021-07-25
  • 2021-08-02
  • 2021-11-06
  • 2022-01-22
  • 2021-12-30
  • 2021-12-31
猜你喜欢
  • 2022-01-07
  • 2021-04-12
  • 2021-04-30
  • 2021-11-06
相关资源
相似解决方案