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 {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ApiServiceApplication.class);
|
||||
//初始化静态私有日志对象, 日志输出的时候,可以打印出日志信息所在api服务应用程序类
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ApiServiceApplication.class, args);
|
||||
}
|
||||
//启动api服务应用程序类参数
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() { //在SpringBoot启动类中注册RestTemplate
|
||||
return new RestTemplate();
|
||||
}
|
||||
//返回一个新的请求
|
||||
|
||||
@Bean
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
//返回日志
|
||||
}
|
|
@ -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();
|
||||
//随机选择一个服务器
|
||||
}
|
||||
}
|
|
@ -4,5 +4,4 @@ spring.servlet.multipart.max-request-size=100MB
|
|||
spring.rabbitmq.host=172.20.80.100
|
||||
spring.rabbitmq.port=5672
|
||||
spring.rabbitmq.username=test
|
||||
spring.rabbitmq.password=test
|
||||
server.port=8081
|
||||
spring.rabbitmq.password=test
|
|
@ -11,15 +11,12 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
@EnableScheduling
|
||||
public class DataServiceApplication {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataServiceApplication.class);
|
||||
//初始化静态私有的日志对象, 日志输出的时候,可以打印出日志信息所在data服务应用程序类
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DataServiceApplication.class, args);
|
||||
}
|
||||
//启动data服务应用程序类参数
|
||||
@Bean
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
//返回日志
|
||||
}
|
|
@ -9,6 +9,7 @@ import java.net.InetAddress;
|
|||
|
||||
@Component
|
||||
public class Sender {
|
||||
// 心跳发送端关键代码
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
@Autowired
|
Loading…
Reference in New Issue