非java应用,如何使用eureka的rest api来操作eureka?
2023-09-11 14:14:16 时间
其实这是一个非常有意思的问题······
对于大多数非开发的运维来说,有需要维护的eureka服务的场景,那么,问题是:如何才能对eureka进行运维?首要的条件是什么呢?
没错,就是eureka,了解其中的参数,了解客户端注册的时候,到底注册了哪些的信息,如果对这个信息有非常充分的了解了,那么自然,对于eureka的运行也会有更加深刻的理解,那么接下来的文章中,我们就来看看如何通过eureka的接口来获取应用的信息,以及怎么进行注册、删除。
先来看看eureka的提供的一些接口。
- 查询所有应用的实例
get /eureka/v2/apps
<applications> <versions__delta>1</versions__delta> <apps__hashcode>UP_3_</apps__hashcode> <application> <name>ZHAIMM2</name> <instance> <instanceId>nctest-snap-zhaimm</instanceId> <hostName>nctest-snap-test-02</hostName> <app>ZHAIMM2</app> <ipAddr>172.20.58.152</ipAddr> <status>UP</status> <overriddenstatus>UNKNOWN</overriddenstatus> <port enabled="true">8080</port> <securePort enabled="false">443</securePort> <countryId>1</countryId> <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"> <name>MyOwn</name> </dataCenterInfo> <leaseInfo> <renewalIntervalInSecs>30</renewalIntervalInSecs> <durationInSecs>90</durationInSecs> <registrationTimestamp>1659593782745</registrationTimestamp> <lastRenewalTimestamp>1659593782745</lastRenewalTimestamp> <evictionTimestamp>0</evictionTimestamp> <serviceUpTimestamp>1659593297381</serviceUpTimestamp> </leaseInfo> <metadata class="java.util.Collections$EmptyMap"/> <appGroupName>UNKNOWN</appGroupName> <homePageUrl>http://nctest-snap-test-02:8080/</homePageUrl> <statusPageUrl>http://nctest-snap-test-02:8080/Status</statusPageUrl> <healthCheckUrl>http://nctest-snap-test-02:8080/healthcheck</healthCheckUrl> <vipAddress>eureka.mydomain.net</vipAddress> <isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer> <lastUpdatedTimestamp>1659593782745</lastUpdatedTimestamp> <lastDirtyTimestamp>1659505507804</lastDirtyTimestamp> <actionType>ADDED</actionType> </instance> </application> <application> <name>EUREKA</name> <instance> <instanceId>nctest-snap-test-02</instanceId> <hostName>nctest-snap-test-02</hostName> <app>EUREKA</app> <ipAddr>172.20.58.152</ipAddr> <status>UP</status> <overriddenstatus>UNKNOWN</overriddenstatus> <port enabled="true">8080</port> <securePort enabled="false">443</securePort> <countryId>1</countryId> <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"> <name>MyOwn</name> </dataCenterInfo> <leaseInfo> <renewalIntervalInSecs>30</renewalIntervalInSecs> <durationInSecs>90</durationInSecs> <registrationTimestamp>1659505508457</registrationTimestamp> <lastRenewalTimestamp>1659593867486</lastRenewalTimestamp> <evictionTimestamp>0</evictionTimestamp> <serviceUpTimestamp>1659505507898</serviceUpTimestamp> </leaseInfo> <metadata class="java.util.Collections$EmptyMap"/> <appGroupName>UNKNOWN</appGroupName> <homePageUrl>http://nctest-snap-test-02:8080/</homePageUrl> <statusPageUrl>http://nctest-snap-test-02:8080/Status</statusPageUrl> <healthCheckUrl>http://nctest-snap-test-02:8080/healthcheck</healthCheckUrl> <vipAddress>eureka.mydomain.net</vipAddress> <isCoordinatingDiscoveryServer>true</isCoordinatingDiscoveryServer> <lastUpdatedTimestamp>1659505508457</lastUpdatedTimestamp> <lastDirtyTimestamp>1659505507804</lastDirtyTimestamp> <actionType>ADDED</actionType> </instance> </application> <application> <name>ZHAIMM</name> <instance> <instanceId>nctest-snap-zhaimm</instanceId> <hostName>nctest-snap-test-02</hostName> <app>ZHAIMM</app> <ipAddr>172.20.58.152</ipAddr> <status>UP</status> <overriddenstatus>UNKNOWN</overriddenstatus> <port enabled="true">8080</port> <securePort enabled="false">443</securePort> <countryId>1</countryId> <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"> <name>MyOwn</name> </dataCenterInfo> <leaseInfo> <renewalIntervalInSecs>30</renewalIntervalInSecs> <durationInSecs>90</durationInSecs> <registrationTimestamp>1659593278568</registrationTimestamp> <lastRenewalTimestamp>1659593278568</lastRenewalTimestamp> <evictionTimestamp>0</evictionTimestamp> <serviceUpTimestamp>1659593261166</serviceUpTimestamp> </leaseInfo> <metadata class="java.util.Collections$EmptyMap"/> <appGroupName>UNKNOWN</appGroupName> <homePageUrl>http://nctest-snap-test-02:8080/</homePageUrl> <statusPageUrl>http://nctest-snap-test-02:8080/Status</statusPageUrl> <healthCheckUrl>http://nctest-snap-test-02:8080/healthcheck</healthCheckUrl> <vipAddress>eureka.mydomain.net</vipAddress> <isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer> <lastUpdatedTimestamp>1659593278568</lastUpdatedTimestamp> <lastDirtyTimestamp>1659505507804</lastDirtyTimestamp> <actionType>ADDED</actionType> </instance> </application> </applications>
查询出来的是所有的应用的注册的信息。
- 查询某个特定的应用
get /eureka/v2/apps/<app名字>
<application> <name>EUREKA</name> <instance> <instanceId>nctest-snap-test-02</instanceId> <hostName>nctest-snap-test-02</hostName> <app>EUREKA</app> <ipAddr>172.20.58.152</ipAddr> <status>UP</status> <overriddenstatus>UNKNOWN</overriddenstatus> <port enabled="true">8080</port> <securePort enabled="false">443</securePort> <countryId>1</countryId> <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"> <name>MyOwn</name> </dataCenterInfo> <leaseInfo> <renewalIntervalInSecs>30</renewalIntervalInSecs> <durationInSecs>90</durationInSecs> <registrationTimestamp>1659505508457</registrationTimestamp> <lastRenewalTimestamp>1659593987495</lastRenewalTimestamp> <evictionTimestamp>0</evictionTimestamp> <serviceUpTimestamp>1659505507898</serviceUpTimestamp> </leaseInfo> <metadata class="java.util.Collections$EmptyMap"/> <appGroupName>UNKNOWN</appGroupName> <homePageUrl>http://nctest-snap-test-02:8080/</homePageUrl> <statusPageUrl>http://nctest-snap-test-02:8080/Status</statusPageUrl> <healthCheckUrl>http://nctest-snap-test-02:8080/healthcheck</healthCheckUrl> <vipAddress>eureka.mydomain.net</vipAddress> <isCoordinatingDiscoveryServer>true</isCoordinatingDiscoveryServer> <lastUpdatedTimestamp>1659505508457</lastUpdatedTimestamp> <lastDirtyTimestamp>1659505507804</lastDirtyTimestamp> <actionType>ADDED</actionType> </instance> </application>
这样得到的结果,就是具体的某个应用的信息。
- 查询某个应用的某个特定的实例
get /eureka/v2/apps/<app名字>/<实例ID>
<instance> <instanceId>nctest-snap-test-02</instanceId> <hostName>nctest-snap-test-02</hostName> <app>EUREKA</app> <ipAddr>172.20.58.152</ipAddr> <status>UP</status> <overriddenstatus>UNKNOWN</overriddenstatus> <port enabled="true">8080</port> <securePort enabled="false">443</securePort> <countryId>1</countryId> <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"> <name>MyOwn</name> </dataCenterInfo> <leaseInfo> <renewalIntervalInSecs>30</renewalIntervalInSecs> <durationInSecs>90</durationInSecs> <registrationTimestamp>1659505508457</registrationTimestamp> <lastRenewalTimestamp>1659594497540</lastRenewalTimestamp> <evictionTimestamp>0</evictionTimestamp> <serviceUpTimestamp>1659505507898</serviceUpTimestamp> </leaseInfo> <metadata class="java.util.Collections$EmptyMap"/> <appGroupName>UNKNOWN</appGroupName> <homePageUrl>http://nctest-snap-test-02:8080/</homePageUrl> <statusPageUrl>http://nctest-snap-test-02:8080/Status</statusPageUrl> <healthCheckUrl>http://nctest-snap-test-02:8080/healthcheck</healthCheckUrl> <vipAddress>eureka.mydomain.net</vipAddress> <isCoordinatingDiscoveryServer>true</isCoordinatingDiscoveryServer> <lastUpdatedTimestamp>1659505508457</lastUpdatedTimestamp> <lastDirtyTimestamp>1659505507804</lastDirtyTimestamp> <actionType>ADDED</actionType> </instance>
- 注册某个应用
POST /eureka/v2/apps/<应用ID>
BODY如下:
<instance> <instanceId>zhaimm01</instanceId> <hostName>nctest-snap-test-02</hostName> <app>ZHAIMMTEST</app> <ipAddr>172.20.58.152</ipAddr> <status>UP</status> <overriddenstatus>UNKNOWN</overriddenstatus> <port enabled="true">8080</port> <securePort enabled="false">443</securePort> <countryId>1</countryId> <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"> <name>MyOwn</name> </dataCenterInfo> <leaseInfo> <renewalIntervalInSecs>30</renewalIntervalInSecs> <durationInSecs>90</durationInSecs> <registrationTimestamp>1659505508457</registrationTimestamp> <lastRenewalTimestamp>1659593267433</lastRenewalTimestamp> <evictionTimestamp>0</evictionTimestamp> <serviceUpTimestamp>1659505507898</serviceUpTimestamp> </leaseInfo> <metadata class="java.util.Collections$EmptyMap"/> <appGroupName>UNKNOWN</appGroupName> <homePageUrl>http://nctest-snap-test-02:8080/</homePageUrl> <statusPageUrl>http://nctest-snap-test-02:8080/Status</statusPageUrl> <healthCheckUrl>http://nctest-snap-test-02:8080/healthcheck</healthCheckUrl> <vipAddress>eureka.mydomain.net</vipAddress> <isCoordinatingDiscoveryServer>true</isCoordinatingDiscoveryServer> <lastUpdatedTimestamp>1659505508457</lastUpdatedTimestamp> <lastDirtyTimestamp>1659505507804</lastDirtyTimestamp> <actionType>ADDED</actionType> </instance>
注册中心,可以看到这个应用和对应的实例信息。
多个实例,循环执行上面的注册过程就可以了。
- 删除某个应用的某个实例
DELETE /eureka/v2/apps/appID/instanceID
当所有的实例,都被删除后,应用也就不存在了。
OK,如果以上的东西,你都掌握了,通过api的方式,就可以轻而易举的操作eureka了。
对于非java应用,可以轻松的通过eureka来实现服务、发现了。
相关文章
- java虚拟机学习-JVM内存管理:深入Java内存区域与OOM(3)
- java安全编码指南之:声明和初始化
- java之UDP(datagramsocket,datagramPacket)实例
- 【JAVA】JSP操作数据库简单实例和mysql-connector-java-5.0.3-bin.jar项目配置方法
- Eureka之IpAddress:eureka.instance.prefer-ip-address = true
- Java反编译生成java文件
- [转]Java中继承、多态、重载和重写介绍
- Java 多态 polymorphic 枚举 练习
- Java项目(前端vue后台java微服务)在线考试系统(java+vue+springboot+mysql+maven)
- Java开发环境的搭建以及使用eclipse从头一步步创建java项目
- Java-struts2的问题 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
- Java IDEA中设置导入import java.xx.*和设置导入具体的import java.xx.yy;
- JAVA中sort()排序解析
- 在java中使用JMH(Java Microbenchmark Harness)做性能测试
- Java_jdbc 基础笔记之九 数据库连接 (查询Customer对象的方法)
- Java之Date Time API (Java 8 新特性)
- 『Java练习生的自我修养』java-se进阶⁵ • 常用IO流
- 用Java调用C语言代码实例(JNI)
- Java hutool/java 常用方法