Skip to content

disable服务时报错 #2

Open
Open

Description

@yyi

eureka、client版本为springboot 2.0.x,禁用服务时报:
java.io.FileNotFoundException: http://192.168.1.8:8081/service-registry/instance-status

Activity

  1. walkerzhao commented on Jan 11, 2019

    @walkerzhao

    eureka、client版本为springboot 2.0.x,禁用服务时报:
    java.io.FileNotFoundException: http://192.168.1.8:8081/service-registry/instance-status

    你搜索example里的demo,可以发现
    service-registry/instance-status 这个接口的实现来自ServiceRegistryEndpoint类
    较低的版本里,可能没有这个类的实现

    所以,我建议,这里摘除服务可以使用https://github.com/Netflix/eureka/wiki/Eureka-REST-operations

    我们团队是使用这个接口来操作的

    Take instance out of service PUT /eureka/v2/apps/appID/instanceID/status?value=OUT_OF_SERVICE HTTP 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
  2. walkerzhao commented on Jan 12, 2019

    @walkerzhao

    重写一下那个enable和disable调用的controller,可能更通用一些.

    	@RequestMapping(value = "status/{appName}", method = RequestMethod.POST)
    	public ResultMap servStatus(@PathVariable String appName, String instanceId, String status){
    		log.info("appName:{} instanceId:{} status:{} defaultZone:{}",
    				new Object[] {appName, instanceId, status,defaultZone});
    
    		//拼凑url
    		String url= defaultZone;
    		String outOfServiceUrl = defaultZone + "apps/%s/%s/status?value=OUT_OF_SERVICE";
    		String upUrl = defaultZone + "apps/%s/%s/status?value=UP";
    
    		if(status.equalsIgnoreCase("UP")) {
    			//curl -v -X DELETE "127.0.0.1:9500/eureka/apps/CLIENT-A/192.168.1.101:client-a:7070/status?value=UP"
    			upUrl = String.format(upUrl, appName, instanceId);
    			HttpUtil.delete(upUrl, null, null, null, "UTF-8");
    		} else if(status.equalsIgnoreCase("OUT_OF_SERVICE")) {
    			outOfServiceUrl = String.format(outOfServiceUrl,appName,instanceId);
    			//curl -v -X PUT "127.0.0.1:9500/eureka/apps/CLIENT-A/192.168.1.101:client-a:7070/status?value=OUT_OF_SERVICE"
    			HttpUtil.put(outOfServiceUrl,null,null,null,"UTF-8");
    		}
    
    
    
    		return ResultMap.buildSuccess();
    	}
    
  3. zypabc1234 commented on Feb 14, 2019

    @zypabc1234

    servStatus () 这个方法重写的是哪个类里面的

  4. walkerzhao commented on Feb 15, 2019

    @walkerzhao

    servStatus () 这个方法重写的是哪个类里面的

    EurekaClientController

  5. Andyfan322 commented on May 10, 2019

    @Andyfan322

    倒不如用官方的rest API操作。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions