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