Compare commits
No commits in common. "yqx" and "8d384e3d20a2301bb64f48088676b5aeaec45978" have entirely different histories.
yqx
...
8d384e3d20
|
@ -18,19 +18,18 @@ import java.util.Set;
|
||||||
public class ApiServiceApplication {
|
public class ApiServiceApplication {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ApiServiceApplication.class);
|
private static final Logger logger = LoggerFactory.getLogger(ApiServiceApplication.class);
|
||||||
//初始化静态私有日志对象, 日志输出的时候,可以打印出日志信息所在api服务应用程序类
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ApiServiceApplication.class, args);
|
SpringApplication.run(ApiServiceApplication.class, args);
|
||||||
}
|
}
|
||||||
//启动api服务应用程序类参数
|
|
||||||
@Bean
|
@Bean
|
||||||
public RestTemplate restTemplate() { //在SpringBoot启动类中注册RestTemplate
|
public RestTemplate restTemplate() { //在SpringBoot启动类中注册RestTemplate
|
||||||
return new RestTemplate();
|
return new RestTemplate();
|
||||||
}
|
}
|
||||||
//返回一个新的请求
|
|
||||||
@Bean
|
@Bean
|
||||||
public Logger getLogger() {
|
public Logger getLogger() {
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
//返回日志
|
|
||||||
}
|
}
|
|
@ -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();
|
||||||
|
//随机选择一个服务器
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,5 +4,4 @@ spring.servlet.multipart.max-request-size=100MB
|
||||||
spring.rabbitmq.host=172.20.80.100
|
spring.rabbitmq.host=172.20.80.100
|
||||||
spring.rabbitmq.port=5672
|
spring.rabbitmq.port=5672
|
||||||
spring.rabbitmq.username=test
|
spring.rabbitmq.username=test
|
||||||
spring.rabbitmq.password=test
|
spring.rabbitmq.password=test
|
||||||
server.port=8081
|
|
|
@ -11,15 +11,12 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class DataServiceApplication {
|
public class DataServiceApplication {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DataServiceApplication.class);
|
private static final Logger logger = LoggerFactory.getLogger(DataServiceApplication.class);
|
||||||
//初始化静态私有的日志对象, 日志输出的时候,可以打印出日志信息所在data服务应用程序类
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(DataServiceApplication.class, args);
|
SpringApplication.run(DataServiceApplication.class, args);
|
||||||
}
|
}
|
||||||
//启动data服务应用程序类参数
|
|
||||||
@Bean
|
@Bean
|
||||||
public Logger getLogger() {
|
public Logger getLogger() {
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
//返回日志
|
|
||||||
}
|
}
|
|
@ -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