eureka-admin icon indicating copy to clipboard operation
eureka-admin copied to clipboard

disable服务时报错

Open yyi opened this issue 6 years ago • 5 comments

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

yyi avatar Oct 13 '18 16:10 yyi

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

walkerzhao avatar Jan 11 '19 07:01 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();
	}

walkerzhao avatar Jan 12 '19 15:01 walkerzhao

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

zypabc1234 avatar Feb 14 '19 07:02 zypabc1234

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

EurekaClientController

walkerzhao avatar Feb 15 '19 07:02 walkerzhao

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

Andyfan322 avatar May 10 '19 07:05 Andyfan322