Compare commits
No commits in common. "yqx" and "wdl" have entirely different histories.
|
@ -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;
|
||||
}
|
||||
//返回日志
|
||||
}
|
|
@ -43,6 +43,7 @@ public class ObjectsController {
|
|||
|
||||
@PutMapping("/objects/{filename}")
|
||||
public String putObject(@RequestBody byte[] requestBody, @RequestHeader Map<String, String> headers, @PathVariable("filename") String filename) throws IOException {
|
||||
// 改进函数,支持多个服务器
|
||||
String server = this.dataServerStore.selectRandomServer();
|
||||
logger.info("put object to server: " + server);
|
||||
if (server == null) {
|
||||
|
@ -60,6 +61,7 @@ public class ObjectsController {
|
|||
public String getObject(HttpServletResponse response, @PathVariable("filename") String filename) throws IOException {
|
||||
// 查询哪台服务器有这个文件
|
||||
// 读取文件
|
||||
// 改进函数,支持多个服务器
|
||||
String queueName = filename;
|
||||
Channel channel = rabbitTemplate.getConnectionFactory().createConnection().createChannel(false);
|
||||
channel.queueDeclare(queueName, false, false, false, null);
|
|
@ -12,6 +12,7 @@ import javax.annotation.Resource;
|
|||
@Component
|
||||
@RabbitListener(queues = "apiServers")
|
||||
public class Receiver {
|
||||
//心跳接收端关键代码
|
||||
@Autowired
|
||||
private DataServerStore dataServerStore;
|
||||
@RabbitHandler
|
|
@ -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