| | |
| | | import com.xcong.excoin.modules.station.model.GateStatsEvent; |
| | | import com.xcong.excoin.modules.station.model.HeartbeatMsg; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.core.env.Environment; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | |
| | | @Resource |
| | | private GateWebSocketClientManager manager; |
| | | |
| | | @Resource |
| | | private Environment environment; |
| | | |
| | | private String apiKeyMd5; |
| | | private String hostPort; |
| | |
| | | GateStatsEvent event = statsProducer.newHeartbeat(apiKeyMd5, hb); |
| | | statsProducer.sendHeartbeat(event); |
| | | |
| | | log.info("[Gate] 心跳已发送, state={}, apiKeyMd5={}", state, apiKeyMd5); |
| | | // log.info("[Gate] 心跳已发送, state={}, apiKeyMd5={}", state, apiKeyMd5); |
| | | } catch (Exception e) { |
| | | log.warn("[Gate] 心跳发送失败", e); |
| | | } |
| | |
| | | private String resolveHostPort() { |
| | | try { |
| | | String host = InetAddress.getLocalHost().getHostAddress(); |
| | | // port 从 Spring 环境变量获取,默认 8888 |
| | | String port = System.getProperty("server.port", "8888"); |
| | | // port 从 Spring Environment 获取(兼容 --server.port=xxx 命令行参数),默认 8888 |
| | | String port = environment.getProperty("server.port", "8888"); |
| | | return host + ":" + port; |
| | | } catch (Exception e) { |
| | | return "unknown"; |