郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.gkhy.safePlatform.controller;
 
import com.alibaba.nacos.api.exception.NacosException;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.service.WebsocketServerNamingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@RequestMapping(value = "/ws/namesrv")
public class WebsocketNamingServiceController {
 
    @Value("${websocket.server.safecheck}")
    private String serverName;
 
    @Autowired
    private WebsocketServerNamingService websocketServerNamingService;
 
    @GetMapping("/get/list")
    public Object getSelfServiceList() throws NacosException {
        ResultVO resultVO = websocketServerNamingService.listHealthyInstance(serverName);
        return resultVO;
    }
 
    @GetMapping("/get/one")
    public Object getSelfServiceOne(String srv) throws NacosException {
        ResultVO resultVO = new ResultVO<>();
        resultVO.setCode(ResultCodes.OK.getCode());
        if(srv == null || srv.isEmpty()){
            return resultVO;
        }
        if(srv.equals(serverName)){
            resultVO = websocketServerNamingService.getOneHealthyInstance(serverName);
        }
        return resultVO;
    }
}