Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable服务时报错 #2

Open
yyi opened this issue Oct 13, 2018 · 5 comments
Open

disable服务时报错 #2

yyi opened this issue Oct 13, 2018 · 5 comments

Comments

@yyi
Copy link

yyi commented Oct 13, 2018

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

@walkerzhao
Copy link

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
Copy link

重写一下那个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();
	}

@zypabc1234
Copy link

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

@walkerzhao
Copy link

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

EurekaClientController

@Andyfan322
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants