begin new project
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user