liusuyi
2026-06-11 b097f7539a7429a85cdda7959c9ecb83a37a2918
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
package com.ard.work.component.forest;
 
import com.ard.work.domain.entity.ArdServerInfo;
import com.ard.work.service.IArdServerInfoService;
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
@Slf4j
@Component
public class MyAddressSource implements AddressSource {
 
    @Resource
    private IArdServerInfoService ardServerService;
    @Override
    public ForestAddress getAddress(ForestRequest request) {
        String serverKey = request.varAsString("serverId");
        if(serverKey == null){
            log.warn("请求属性serverId为空");
            return null;
        }
        ArdServerInfo serverInfo = ardServerService.selectArdServerInfoById(serverKey);
        if(serverInfo == null){
            log.warn("边缘服务器不存在");
            return null;
        }
        // 返回 Forest 地址对象
        return new ForestAddress(serverInfo.getHost(), serverInfo.getHttpPort());
    }
}