• Eureka 笔记


    服务端:

    创建springBoot 项目

    1.步骤 导入在pom.xml中         导入        eureka-server的 jar包

    2.步骤 在主方法加注解        @EnableEurekaServer

    3. 步骤 在配置config

    1.步骤pox.xml:

    1. "1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0modelVersion>
    5. <parent>
    6. <groupId>org.springframework.bootgroupId>
    7. <artifactId>spring-boot-starter-parentartifactId>
    8. <version>3.1.3version>
    9. <relativePath/>
    10. parent>
    11. <groupId>com.csdngroupId>
    12. <artifactId>springboot-ms-eureka-serverartifactId>
    13. <version>0.0.1-SNAPSHOTversion>
    14. <packaging>warpackaging>
    15. <name>springboot-ms-eureka-servername>
    16. <description>eureka服务端description>
    17. <properties>
    18. <java.version>17java.version>
    19. <spring-cloud.version>2022.0.4spring-cloud.version>
    20. properties>
    21. <dependencies>
    22. <dependency>
    23. <groupId>org.springframework.bootgroupId>
    24. <artifactId>spring-boot-starter-webartifactId>
    25. dependency>
    26. <dependency>
    27. <groupId>org.springframework.cloudgroupId>
    28. <artifactId>spring-cloud-starter-netflix-eureka-serverartifactId>
    29. dependency>
    30. <dependency>
    31. <groupId>org.springframework.bootgroupId>
    32. <artifactId>spring-boot-starter-tomcatartifactId>
    33. <scope>providedscope>
    34. dependency>
    35. <dependency>
    36. <groupId>org.springframework.bootgroupId>
    37. <artifactId>spring-boot-starter-testartifactId>
    38. <scope>testscope>
    39. dependency>
    40. dependencies>
    41. <dependencyManagement>
    42. <dependencies>
    43. <dependency>
    44. <groupId>org.springframework.cloudgroupId>
    45. <artifactId>spring-cloud-dependenciesartifactId>
    46. <version>${spring-cloud.version}version>
    47. <type>pomtype>
    48. <scope>importscope>
    49. dependency>
    50. dependencies>
    51. dependencyManagement>
    52. <build>
    53. <plugins>
    54. <plugin>
    55. <groupId>org.springframework.bootgroupId>
    56. <artifactId>spring-boot-maven-pluginartifactId>
    57. plugin>
    58. plugins>
    59. build>
    60. project>

    2.步骤 :加注解@EnableEurekaServer

    1. package com.csdn;
    2. import org.springframework.boot.SpringApplication;
    3. import org.springframework.boot.autoconfigure.SpringBootApplication;
    4. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    5. @SpringBootApplication
    6. @EnableEurekaServer //2步骤 加注解@EnableEurekaServer
    7. public class MainApplication {
    8. public static void main(String[] args) {
    9. SpringApplication.run(MainApplication .class, args);
    10. }
    11. }

    3. 步骤 : resources/application.properties 进行配置

    1. # 3. 步骤config 配置
    2. #eureka服务端应用的端口默认是8761
    3. server.port=9000
    4. #表示是否将自己注册到Eureka Server,默认为true,由于当前应用就是Eureka Server,故而设为false
    5. eureka.client.register-with-eureka=false
    6. # 表示是否从Eureka Server获取注册信息,默认为true,因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而设为false
    7. eureka.client.fetch-registry=false
    8. #暴露给其他eureka client客户端 的注册地址
    9. eureka.client.service-url.defaultZone: http://localhost:9000/eureka/

    客户端:

    1.步骤 导入在pom.xml中         导入        eureka-client的 jar包

    1. <dependency>
    2. <groupId>org.springframework.cloudgroupId>
    3. <artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
    4. dependency>

    2. 步骤 : resources/application.properties 进行配置

    1. # 3. 步骤config 配置
    2. server.port=8001
    3. #注册到eureka服务端的微服务名称
    4. spring.application.name=ms-consumer-user
    5. #注册到eureka服务端的地址
    6. eureka.client.service-url.defaultZone=http://localhost:9000/eureka/
    7. #点击具体的微服务,右下角是否显示ip
    8. eureka.instance.prefer-ip-address=true
    9. #显示微服务的名称
    10. eureka.instance.instance-id=ms-consumer-user-8001

    URL访问地址:http://localhost:9000/

    OperationHTTP actionDescription
    Register new application instancePOST /eureka/v2/apps/appIDInput: JSON/XMLpayload HTTP Code: 204 on success
    De-register application instanceDELETE /eureka/v2/apps/appID/instanceIDHTTP Code: 200 on success
    Send application instance heartbeatPUT /eureka/v2/apps/appID/instanceIDHTTP Code:
    * 200 on success
    * 404 if instanceIDdoesn’t exist
    Query for all instancesGET /eureka/v2/appsHTTP Code: 200 on success Output: JSON/XML
    Query for all appIDinstancesGET /eureka/v2/apps/appIDHTTP Code: 200 on success Output: JSON/XML
    Query for a specific appID/instanceIDGET /eureka/v2/apps/appID/instanceIDHTTP Code: 200 on success Output: JSON/XML
    Query for a specific instanceIDGET /eureka/v2/instances/instanceIDHTTP Code: 200 on success Output: JSON/XML
    Take instance out of servicePUT /eureka/v2/apps/appID/instanceID/status?value=OUT_OF_SERVICEHTTP Code:
    * 200 on success
    * 500 on failure
    Move instance back into service (remove override)DELETE /eureka/v2/apps/appID/instanceID/status?value=UP (The value=UP is optional, it is used as a suggestion for the fallback status due to removal of the override)HTTP Code:
    * 200 on success
    * 500 on failure
    Update metadataPUT /eureka/v2/apps/appID/instanceID/metadata?key=valueHTTP Code:
    * 200 on success
    * 500 on failure
    Query for all instances under a particular vip addressGET /eureka/v2/vips/vipAddress
    * HTTP Code: 200 on success Output: JSON/XML 
    * 404 if the vipAddress does not exist.
    Query for all instances under a particular secure vip addressGET /eureka/v2/svips/svipAddress
    * HTTP Code: 200 on success Output: JSON/XML 
    * 404 if the svipAddress does not exist.
  • 相关阅读:
    Go 语言搭建个人博客(qiucode.cn 重构篇 二)
    计算机组成原理——数的表示与计算
    关于Python和自动化
    基于nacos netflix loadbalancer灰度发布策略
    Uptime Kuma 使用指南:一款简单易用的站点监控工具
    Android 编译C++
    raw照片智能处理软件 DxO PureRAW mac中文版高级功能
    JavaScript 前端枚举库 js-enumerate
    spring security 用户认证原理
    【分治算法】【Python实现】二分搜索
  • 原文地址:https://blog.csdn.net/jiayou2020527/article/details/132782006