This commit is contained in:
parent
3f08420659
commit
8d384e3d20
|
@ -12,6 +12,7 @@ import javax.annotation.Resource;
|
|||
@Component
|
||||
@RabbitListener(queues = "apiServers")
|
||||
public class Receiver {
|
||||
//心跳接收端关键代码
|
||||
@Autowired
|
||||
private DataServerStore dataServerStore;
|
||||
@RabbitHandler
|
|
@ -13,12 +13,14 @@ public class DataServerStore {
|
|||
|
||||
public synchronized void receivedHeart(String addr) {
|
||||
this.serverHeart.put(addr, System.currentTimeMillis() / 1000);
|
||||
// 保存服务端心跳
|
||||
}
|
||||
public Map<String,Long> getServerHeart(){
|
||||
return this.serverHeart;
|
||||
}
|
||||
Set<String> getServerList() {
|
||||
return this.serverHeart.keySet();
|
||||
// 获取服务器列表
|
||||
}
|
||||
|
||||
public String selectRandomServer() {
|
||||
|
@ -28,5 +30,6 @@ public class DataServerStore {
|
|||
}
|
||||
int index = (int) (Math.random() * serverList.size());
|
||||
return serverList.toArray()[index].toString();
|
||||
//随机选择一个服务器
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import java.net.InetAddress;
|
|||
|
||||
@Component
|
||||
public class Sender {
|
||||
// 心跳发送端关键代码
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
@Autowired
|
Loading…
Reference in New Issue