序
本文主要研究下Eureka Server的REST API
ApplicationsResource
eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/ApplicationsResource.java
@Path("/{version}/apps")@Produces({ "application/xml", "application/json"})public class ApplicationsResource { @Path("{appId}") public ApplicationResource getApplicationResource( @PathParam("version") String version, @PathParam("appId") String appId) { CurrentRequestVersion.set(Version.toEnum(version)); return new ApplicationResource(appId, serverConfig, registry); } //... @GET public Response getContainers(@PathParam("version") String version, @HeaderParam(HEADER_ACCEPT) String acceptHeader, @HeaderParam(HEADER_ACCEPT_ENCODING) String acceptEncoding, @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept, @Context UriInfo uriInfo, @Nullable @QueryParam("regions") String regionsStr) { //... } @Path("delta") @GET public Response getContainerDifferential( @PathParam("version") String version, @HeaderParam(HEADER_ACCEPT) String acceptHeader, @HeaderParam(HEADER_ACCEPT_ENCODING) String acceptEncoding, @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept, @Context UriInfo uriInfo, @Nullable @QueryParam("regions") String regionsStr) { //... } }复制代码
这里提供三个接口:
- /{version}/apps/{appId}
- /{version}/apps
- /{version}/apps/delta
对于spring cloud eureka来说,这里的version是eureka
ApplicationResource
eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/ApplicationResource.java
@GET public Response getApplication(@PathParam("version") String version, @HeaderParam("Accept") final String acceptHeader, @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) { //... } @Path("{id}") public InstanceResource getInstanceInfo(@PathParam("id") String id) { return new InstanceResource(this, id, serverConfig, registry); } @POST @Consumes({ "application/json", "application/xml"}) public Response addInstance(InstanceInfo info, @HeaderParam(PeerEurekaNode.HEADER_REPLICATION) String isReplication) { //... } 复制代码
这里提供三个接口
- /{version}
- /{id}
- POST /
InstancesResource
eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/InstancesResource.java
@Produces({ "application/xml", "application/json"})@Path("/{version}/instances")public class InstancesResource { @GET @Path("{id}") public Response getById(@PathParam("version") String version, @PathParam("id") String id) { //... }}复制代码
这里提供一个接口
- /{version}/instances/{id}
StatusResource
eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/StatusResource.java
@Path("/{version}/status")@Produces({ "application/xml", "application/json"})public class StatusResource { @GET public StatusInfo getStatusInfo() { return statusUtil.getStatusInfo(); } //...}复制代码
这里提供一个接口
- /{version}/status
VIPResource
eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/VIPResource.java
@Path("/{version}/vips")@Produces({ "application/xml", "application/json"})public class VIPResource extends AbstractVIPResource { @GET @Path("{vipAddress}") public Response statusUpdate(@PathParam("version") String version, @PathParam("vipAddress") String vipAddress, @HeaderParam("Accept") final String acceptHeader, @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) { return getVipResponse(version, vipAddress, acceptHeader, EurekaAccept.fromString(eurekaAccept), Key.EntityType.VIP); }}复制代码
这里提供一个接口
- /{version}/vips/{vipAddress}
SecureVIPResource
eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/SecureVIPResource.java
@Path("/{version}/svips")@Produces({ "application/xml", "application/json"})public class SecureVIPResource extends AbstractVIPResource { @GET @Path("{svipAddress}") public Response statusUpdate(@PathParam("version") String version, @PathParam("svipAddress") String svipAddress, @HeaderParam("Accept") final String acceptHeader, @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) { return getVipResponse(version, svipAddress, acceptHeader, EurekaAccept.fromString(eurekaAccept), Key.EntityType.SVIP); }}复制代码
这里提供一个接口
- /{version}/svips/{svipAddress}
PeerReplicationResource
eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/PeerReplicationResource.java
@Path("/{version}/peerreplication")@Produces({ "application/xml", "application/json"})public class PeerReplicationResource { @Path("batch") @POST public Response batchReplication(ReplicationList replicationList) { //.... }}复制代码
这里提供一个接口
- POST /{version}/peerreplication/batch
小结
eureka server的rest api是使用javax.ws实现的。然后spring cloud的版本,其version传的是eureka值。使用javax.ws实现的接口,感觉比起spring mvc来说,非常不好找映射,稍微有点费劲。