Spring?cloud?實現(xiàn)房源查詢功能的實例代碼
前言
這個項目的功能很簡單只涉及了查詢功能,這個項目的的目的是熟悉SpringCloud框架,明白服務與服務之間的調用是通過http請求完成的使用微服務的架構而Feign可以使其像調用本地方法一樣,學會在其他模塊調用另一模塊的服務和內容,完成負載均衡,學會將不同端口注冊到eureka ,了解網(wǎng)關并會配置網(wǎng)關和使用斷路器。
核心組件
服務注冊中心
Spring Cloud Netflix Eureka
服務調用方式
REST API、Feign、 Ribbon
服務網(wǎng)關
Spring Cloud Netflix Zuul
斷路器
Spring Cloud Netflix Hystrix
數(shù)據(jù)庫設計
由于本項目只是為了完整的實現(xiàn)SpringCloud項目并明白框架功能故只設計查詢功能,所以只設計兩張表
表1 house

表2

1 項目搭建
本項目是一個多模塊項目,創(chuàng)建一個 Spring Initializr 項目 不自動添加依賴項,完成創(chuàng)建后刪除自帶的src目錄,并在根目錄下創(chuàng)建新的maven模塊。
1.1添加依賴
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<packaging>pom</packaging>
<modules>
<module>house-server</module>
<module>eureak-server</module>
<module>house-zuul</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xatu</groupId>
<artifactId>spring-cloud-house-test1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-cloud-house-test1</name>
<description>spring-cloud-house-test1</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2 開發(fā)房源查詢模塊:
2.1 house-list 模塊
2.1.1模塊總覽:

端口號 8081 url接口 /house
參數(shù)名稱 :null
參數(shù)類型 : null
說明 : 找到上線房源 打印list
2 .1.2寫配置文件
創(chuàng)建application.properties
?server.port=8081
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/house_test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.username=root
spring.datasource.password=123456
logging.pattern.console=%clr(%d{${LOG_DATEFORMAT_PATTERN:HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}
mybatis.configuration.map-underscore-to-camel-case=true
spring.application.name=house-list
eureka.client.service-url.defaultZone=http://localhost:8000/eureka/2.1.3 依賴項配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>house-server</artifactId>
<groupId>com.xatu</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>houser-list</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<!-- eureka-client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>2.1.3 啟動類
/**
* 描述: 項目啟動類
*/
@SpringBootApplication
@EnableEurekaClient
public class HouseListApplication {
public static void main(String[] args) {
SpringApplication.run(HouseListApplication.class, args);
}2.1.4 controller
/**
* 描述: CourseListController課程列表Controller
*/
@RestController//將返結果是json對象
public class HouseListController {
@Autowired
HouseListService houseListService;
@GetMapping("/house")
public List<House> houseList() {
return houseListService.getCourseList();
}
}2.1.5 創(chuàng)建entity實體類,實現(xiàn)set /get 方法并用自動生成重寫toString方法。
/**
* 描述: House實體類
*/
public class House implements Serializable {
Integer id;
Integer houseId;
String houseName;
Integer valid;
@Override
public String toString() {
return "Course{" +
"id=" + id +
", courseId=" + houseId +
", courseName='" + houseName + '\'' +
", valid=" + valid +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getHouseId() {
return houseId;
}
public void setHouseId(Integer houseId) {
this.houseId = houseId;
}
public String getHouseName() {
return houseName;
}
public void setHouseName(String houseName) {
this.houseName = houseName;
}
public Integer getValid() {
return valid;
}
public void setValid(Integer valid) {
this.valid = valid;
}
}2.1.6 service
/**
* 描述: 房源列表服務
*/
public interface HouseListService {
List<House> getCourseList();
}impl 實現(xiàn)類
@Service
public class HouseListServiceImpl implements HouseListService {
@Autowired
HouseMapper houseMapper;
@Override
public List<House> getCourseList() {
return houseMapper.findValidCourses();
}
}mapper
/**
* 描述: 房源的Mapper類
*/
@Mapper
@Repository
public interface HouseMapper {
@Select("SELECT * FROM house WHERE valid = 1")
List<House> findValidCourses();
}這里實現(xiàn)的是查詢已上線的房源。
2.2 房價模塊
2.2.1 總覽

端口號 8083
url接口 /price
參數(shù)名稱 :houseId
參數(shù)類型 : int
說明 : 獲取到對應房源id的價格
url接口 /HouseInPrice
參數(shù)名稱 :null
參數(shù)類型 : null
說明 : 作用與/list/house類似只是為了測試引入功能
url接口 /houseAndPrice
參數(shù)名稱 :null
參數(shù)類型 : null
說明 : 獲取到房子id 價格 id 名字
2.2.2 配置文件與依賴
server.port=8082
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/house_test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.username=root
spring.datasource.password=123456
logging.pattern.console=%clr(%d{${LOG_DATEFORMAT_PATTERN:HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}
#tuo feng ming ming zhuan huan
mybatis.configuration.map-underscore-to-camel-case=true
spring.application.name=house-price
eureka.client.service-url.defaultZone=http://localhost:8000/eureka/
house-list.ribbon.NFLoadBanlancerRuleClassName=com.netflix.loadbalancer.RoundRobinRule
feign.hystrix.enabled=true<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>house-server</artifactId>
<groupId>com.xatu</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>house-price</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- feign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>com.xatu</groupId>
<artifactId>houser-list</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>2.2.3 啟動類
/**
* 描述: 項目啟動類
*/
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableCircuitBreaker
public class HousePriceApplication {
public static void main(String[] args) {
SpringApplication.run(HousePriceApplication.class, args);
}
}2.2.4 client
/**
* 描述: 房源列表的Feign客戶端
*/
//當遠端服務出現(xiàn)問題會進入這個類
@FeignClient(value = "house-list" ,fallback = HouseListClientHystrix.class)
//有多個實例時,帶有注解的人就是注入的
@Primary
public interface HouseListClient {
@GetMapping("/house")
public List<House> houseList();
}如果不用feign 不同服務是不能進行調用的,我們在需要使用整合服務的模塊中引入依賴 ,我加了注釋了,再在啟動類中加入注解,并創(chuàng)建一個類來作為我們引入模塊的feign客戶端,直接從我們想要引入的服務的controller中復制即可,引入后會有提示,要引入對另一個模塊的依賴,就能數(shù)顯服務的整合了。
/**
* 描述: 斷路器實現(xiàn)類
*/
@Component
public class HouseListClientHystrix implements HouseListClient {
@Override
public List<House> houseList() {
List<House> defaultCourses = new ArrayList<>();
House House = new House();
House.setId(1);
House.setHouseId(1);
House.setHouseName("默認房源");
House.setValid(1);
defaultCourses.add(House);
return defaultCourses;
}
}發(fā)生錯誤時調用的類,給服務的返回是默認的返回值 @Component 注解使它成為一個組件
2.2.5 controller
/**
* 描述: 房價格控制器
*/
@RestController
public class HousePriceController {
@Autowired
HousePriceService housePriceService;
@Autowired
HouseListClient houseListClient;
@GetMapping("/price")
public Integer getCoursePrice(Integer houseId) {
HousePrice housePrice = housePriceService.getHousePrice(houseId);
return housePrice.getPrice();
}
@GetMapping("/HouseInPrice")
public List<House> getHouseListInPrice(Integer houseId) {
List<House> houses = houseListClient.houseList();
return houses;
}
@GetMapping("/houseAndPrice")
public List<HouseAndPrice> getCoursesAndPrice() {
List<HouseAndPrice> houseAndPrice = housePriceService.getHousesAndPrice();
return houseAndPrice;
}
}2.2.6 service
/**
* 描述: 房價格服務
*/
public interface HousePriceService {
HousePrice getHousePrice(Integer houseId);
List<HouseAndPrice> getHousesAndPrice();
List<HousePrice> getHousePriceList();
}impl
/**
* 描述: 課程價格的服務實現(xiàn)類
*/
@Service
public class HousePriceServiceImpl implements HousePriceService {
@Autowired
HousePriceMapper housePriceMapper;
@Autowired
HouseListClient houseListClient;
@Override
public HousePrice getHousePrice(Integer houseId) {
return housePriceMapper.findCoursePrice(houseId);
}
@Override
public List<HouseAndPrice> getHousesAndPrice() {
List<HouseAndPrice> houseAndPricesList = new ArrayList<>();
List<House> houses = houseListClient.houseList();
for(int i = 0;i < houses.size();i++){
House house = houses.get(i);
if(house != null){
HousePrice housePrice = getHousePrice(house.getHouseId());
HouseAndPrice houseAndPrice = new HouseAndPrice();
houseAndPrice.setPrice(housePrice.getPrice());
houseAndPrice.setName(house.getHouseName());
houseAndPrice.setId(house.getId());
houseAndPrice.setHouseId(house.getHouseId());
houseAndPricesList.add(houseAndPrice);
}
}
return houseAndPricesList;
}
@Override
public List<HousePrice> getHousePriceList() {
return housePriceMapper.getAll();
}
}第二個方法就體現(xiàn)除了服務的整合,我們并不用去進行多表查詢,只需要調用其他服務就能快捷完成。
2.2.7 實體類
/**
* 融合類
*
*/
public class HouseAndPrice {
Integer id;
Integer houseId;
String name;
Integer price;
@Override
public String toString() {
return "HouseAndPrice{" +
"id=" + id +
", houseId=" + houseId +
", name='" + name + '\'' +
", price=" + price +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getHouseId() {
return houseId;
}
public void setHouseId(Integer houseId) {
this.houseId = houseId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
}public class HousePrice implements Serializable {
Integer id;
Integer houseId;
Integer price;
@Override
public String toString() {
return "HousePrice{" +
"id=" + id +
", houseId=" + houseId +
", price=" + price +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getHouseId() {
return houseId;
}
public void setHouseId(Integer houseId) {
this.houseId = houseId;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
}2.2.8 mapper
/**
* 描述: 房價格Mapper類
*/
@Mapper
@Repository
public interface HousePriceMapper {
@Select("SELECT * FROM house_price WHERE house_id = #{houseId}")
HousePrice findCoursePrice(Integer courseId);
@Select("SELECT * FROM house_price" )
List<HousePrice> getAll();
}3 Eureka 開發(fā)
Eureka server服務注冊與管理的中心 生產(chǎn)者,提供者
調用方:
提供者把自己的信息注冊到上面,server就能掌握最新的動態(tài),調用方去調用服務是,會先去獲取最新的地址,獲取地址之后再去進行實際的調用。
Eureka 開發(fā)多了獲取地址這一步是對ip服務進行解耦 。
Eureka client改寫
我們把強兩個模塊進行Eureka Client改寫也很簡單,只用在啟動類上加注解
@EnableEurekaClient
在配置文件上進行配置
eureka.client.service-url.defaultZone=http://localhost:8000/eureka/
我們eureka端口號多少8000那項就是多少
3.1模塊總覽

3.2 配置文件與依賴
spring.application.name=eureka-server
server.port=8000
eureka.instance.hostname=localhost
#?????
eureka.client.fetch-registry=false
#?????????
eureka.client.register-with-eureka=false
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/第一個注釋是獲取注冊表。不需要同步其他節(jié)點數(shù)據(jù)
第二個注釋是是否發(fā)自己也注冊上去
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-cloud-house-test1</artifactId>
<groupId>com.xatu</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eureak-server</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<name>course-eureka-server</name>
<description>Spring Cloud Eureka</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>3.3 啟動類
/**
* 描述: Eureka服務端
*/
//eurekaserver啟動
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
這樣就證明我們的服務已經(jīng)注冊上去了
4 負載均衡
4.1負載均衡策略
RandomRule表示隨機策略
RoundRobinRule 表示輪詢策略
Response TimeWeightedRule加權,根據(jù)每一個Server的平均響應時間動態(tài)加權
4.2 為price模塊配置負載均衡
其實就是在配置文件中加一行
house-list.ribbon.NFLoadBanlancerRuleClassName=com.netflix.loadbalancer.RoundRobinRuley意思就是對house-list服務調用的時候采取的負載均衡的策略。
5 斷路器
起到一個兜底的作用,有些時候一個服務出現(xiàn)問題,我們不希望整個系統(tǒng)都崩潰掉,那我們可以采取降級的手段,雖然不能返回正常的數(shù)據(jù)卻可以保證系統(tǒng)正常運行。運用斷路器我們不僅要配置配置文件,加依賴,還要書寫一個短路類(參見price模塊下client 下的斷路器實現(xiàn)類)
6 網(wǎng)關
6.1 模塊總覽

6.2 配置文件與依賴
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-cloud-house-test1</artifactId>
<groupId>com.xatu</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>house-zuul</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- 網(wǎng)關依賴-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>spring.application.name=house-gateway
server.port=9000
logging.pattern.console=%clr(%d{${LOG_DATEFORMAT_PATTERN:HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}
mybatis.configuration.map-underscore-to-camel-case=true
eureka.client.service-url.defaultZone=http://localhost:8000/eureka/
#???????
zuul.prefix=/xatu
zuul.routes.house-list.path=/list/**
zuul.routes.house-list.service-id=house-list
zuul.routes.house-price.path=/price/**
zuul.routes.house-price.service-id=house-price6.3 啟動類
/**
* 描述: 網(wǎng)關啟動類
*/
//網(wǎng)關注解
@EnableZuulProxy
@SpringCloudApplication
public class ZuulGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulGatewayApplication.class, args);
}
}6.4 過濾器
pre 過濾器在路由請求之前運行
route 過濾器可以處理請求的實際路由
post 路由請求后運行過濾器
error如果在處理請求的過程中發(fā)生錯誤,則過濾器將運行
這里寫一個前置一個后置
/**
* 描述: 前置過濾器
*/
@Component
public class PreRequestFilter extends ZuulFilter {
//指定過濾器類別
@Override
public String filterType() {
return FilterConstants.PRE_TYPE;
}
//順序
@Override
public int filterOrder() {
return 5;
}
//是不是走過濾器可以添加判斷
@Override
public boolean shouldFilter() {
return true;
}
//通過過濾器將要實現(xiàn)的邏輯----打印出請求url
@Override
public Object run() throws ZuulException {
RequestContext currentContext = RequestContext.getCurrentContext();
//獲取當前請求uri
System.out.println("URI:" + currentContext.getRequest().getRequestURI());
return null;
}
}/**
* 描述: 后置過濾器
*/
@Component
public class PostRequestFilter extends ZuulFilter {
@Override
public String filterType() {
return FilterConstants.POST_TYPE;
}
@Override
public int filterOrder() {
return FilterConstants.SEND_RESPONSE_FILTER_ORDER - 1;
}
@Override
public boolean shouldFilter() {
return true;
}
//打印返回狀態(tài)碼
@Override
public Object run() throws ZuulException {
RequestContext currentContext = RequestContext.getCurrentContext();
int status = currentContext.getResponse().getStatus();
System.out.println("response status:" + status);
return null;
}
}瀏覽器輸入http://127.0.0.1:9000/xatu/house-list/house


可以看書過濾器也實現(xiàn)了
總結
1 通過這個項目我們了解了SpringCloud的幾個重要組件
2 數(shù)據(jù)流向

3 完成兩個模塊開發(fā)后進行了服務注冊與發(fā)現(xiàn)Eureka
4 為了使服務間調用更加簡便使用了Feign組件
5 使用到了負載均衡
6 使用到了熔斷器
7 使用網(wǎng)關,并進行了過濾器的編寫
到此這篇關于Spring cloud 實現(xiàn)房源查詢功能的文章就介紹到這了,更多相關Spring cloud 房源查詢內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
springboot整合sentinel接口熔斷的實現(xiàn)示例
為了防止慢接口導致的服務阻塞,可以通過添加熔斷處理來避免應用的大量工作線程陷入阻塞,保證其他接口的正常運行,本文介紹了如何使用Spring Boot與Sentinel進行接口熔斷的配置與實現(xiàn),感興趣的可以了解一下2024-09-09
SpringBoot監(jiān)控SQL運行情況的流程步驟
Druid是Java語言中最好的數(shù)據(jù)庫連接池,雖然?HikariCP?的速度稍快,但是,Druid能夠提供強大的監(jiān)控和擴展功能?,也是阿里巴巴的開源項目,本文給大家介紹了SpringBoot監(jiān)控SQL運行情況的流程步驟,需要的朋友可以參考下2024-03-03
解決Springboot 2 的@RequestParam接收數(shù)組異常問題
這篇文章主要介紹了解決Springboot 2 的@RequestParam接收數(shù)組異常問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08
Java語言實現(xiàn)簡單FTP軟件 FTP上傳下載管理模塊實現(xiàn)(11)
這篇文章主要為大家詳細介紹了Java語言實現(xiàn)簡單FTP軟件,F(xiàn)TP本地文件管理模塊的實現(xiàn)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04
SpringBoot集成geodesy實現(xiàn)距離計算功能
Geodesy:大地測量學的神奇力量 Geodesy,又稱大地測量學,是一門研究地球形狀、大小及其重力場的學科,在地球距離計算中,它扮演著至關重要的角色,故本文給大家介紹了SpringBoot集成geodesy實現(xiàn)距離計算功能,感興趣的朋友可以參考下2024-06-06
SpringSecurity整合springBoot、redis實現(xiàn)登錄互踢功能
這篇文章主要介紹了SpringSecurity整合springBoot、redis實現(xiàn)登錄互踢,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-05-05

