入库方法修改为多线程,大幅提高入库效率
This commit is contained in:
@@ -10,6 +10,7 @@ import com.yupi.springbootinit.service.HostInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -39,14 +40,15 @@ public class MQReceiver {
|
||||
// }
|
||||
|
||||
@RabbitListener(queues = "HOST_INFO_QUEUE")
|
||||
@Async
|
||||
public void receive(List<NewHosts> hosts, Channel channel, Message message) throws IOException {
|
||||
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||
try {
|
||||
// 等待所有异步任务完成
|
||||
hostInfoService.processHosts(hosts).join(); // 这里会抛出异常
|
||||
hostInfoService.processHosts(hosts); // 这里会抛出异常
|
||||
channel.basicAck(deliveryTag, false);
|
||||
log.info("deliveryTag:{}", deliveryTag);
|
||||
log.info("{} 消息消费内容大小-------> {}",DateTime.now(),hosts.size());
|
||||
// log.info("deliveryTag:{}", deliveryTag);
|
||||
// log.info("{} 消息消费内容大小-------> {}",DateTime.now(),hosts.size());
|
||||
} catch (Exception e) {
|
||||
channel.basicNack(deliveryTag, false, false);
|
||||
log.error("消息消费失败------->消息内容大小{}", hosts.size(), e);
|
||||
|
||||
Reference in New Issue
Block a user