(@NotNull String serviceName, @NotNull HttpServer httpServer)
| 25 | } |
| 26 | |
| 27 | public void register(@NotNull String serviceName, @NotNull HttpServer httpServer) throws Exception { |
| 28 | var ip = httpServer.getExportIp(); |
| 29 | var port = httpServer.getPort(); |
| 30 | |
| 31 | var serviceId = "@" + ip + ":" + port + "@" + serviceName; // see todo below |
| 32 | if (null != services.putIfAbsent(httpServer, serviceId)) |
| 33 | throw new IllegalStateException("duplicate register " + serviceId); |
| 34 | |
| 35 | httpServer.addHandler(PassiveKeepAlivePath, 1024, null, null, Consul::passiveKeepAlive); |
| 36 | |
| 37 | var newService = new NewService(); |
| 38 | newService.setAddress(ip); |
| 39 | newService.setPort(port); |
| 40 | newService.setId(serviceId); // todo 估计需要唯一。 |
| 41 | newService.setName(serviceName); // todo 这是服务名,一个服务名下有多个Id? |
| 42 | |
| 43 | var checker = new NewService.Check(); |
| 44 | checker.setHttp("http://" + serviceId + PassiveKeepAlivePath); |
| 45 | newService.setCheck(checker); |
| 46 | /* checker 网上的配置,需要都设置? |
| 47 | { |
| 48 | "check": { |
| 49 | "id": "api", |
| 50 | "name": "HTTP API on port 5000", |
| 51 | "http": "https://localhost:5000/health", |
| 52 | "tls_skip_verify": false, |
| 53 | "method": "POST", |
| 54 | "header": {"x-foo":["bar", "baz"]}, |
| 55 | "interval": "10s", |
| 56 | "timeout": "1s" |
| 57 | } |
| 58 | */ |
| 59 | client.agentServiceRegister(newService); // response value is void. |
| 60 | } |
| 61 | |
| 62 | public void stop() { |
| 63 | for (var e : services.entrySet()) { |
nothing calls this directly
no test coverage detected