28 lines
708 B
Java
28 lines
708 B
Java
package com.peanut.modules.springai;
|
|
|
|
import io.modelcontextprotocol.client.McpSyncClient;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
|
|
@Service
|
|
public class McpHeartbeatService {
|
|
|
|
private final List<McpSyncClient> mcpClients;
|
|
|
|
public McpHeartbeatService(List<McpSyncClient> mcpClients) {
|
|
this.mcpClients = mcpClients;
|
|
}
|
|
|
|
@Scheduled(fixedRate = 120000) // 每2分钟1次发送心跳
|
|
public void sendHeartbeat() {
|
|
try {
|
|
this.mcpClients.parallelStream().forEach(client -> {client.ping();});
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
}
|