添加大哥数据入库接口
This commit is contained in:
@@ -6,7 +6,9 @@ import com.rabbitmq.client.Channel;
|
||||
import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import com.yupi.springbootinit.model.entity.NewHosts;
|
||||
import com.yupi.springbootinit.model.entity.ServerBigBrother;
|
||||
import com.yupi.springbootinit.service.HostInfoService;
|
||||
import com.yupi.springbootinit.service.ServerBigBrotherService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
@@ -23,6 +25,9 @@ public class MQReceiver {
|
||||
@Resource
|
||||
private HostInfoService hostInfoService;
|
||||
|
||||
@Resource
|
||||
private ServerBigBrotherService serverBigBrotherService;
|
||||
|
||||
|
||||
// //方法:接收消息
|
||||
// @RabbitListener(queues = "HOST_INFO_QUEUE")
|
||||
@@ -55,4 +60,21 @@ public class MQReceiver {
|
||||
throw new BusinessException(ErrorCode.QUEUE_CONSUMPTION_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@RabbitListener(queues = "BIG_BROTHER_QUEUE")
|
||||
@Async
|
||||
public void bigBrotherReceive(ServerBigBrother bigBrotherList, Channel channel, Message message) throws IOException {
|
||||
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||
try {
|
||||
// 等待所有异步任务完成
|
||||
serverBigBrotherService.saveData(bigBrotherList);
|
||||
channel.basicAck(deliveryTag, false);
|
||||
// log.info("deliveryTag:{}", deliveryTag);
|
||||
// log.info("{} 消息消费内容大小-------> {}",DateTime.now(),hosts.size());
|
||||
} catch (Exception e) {
|
||||
channel.basicNack(deliveryTag, false, false);
|
||||
log.error("消息消费失败");
|
||||
throw new BusinessException(ErrorCode.QUEUE_CONSUMPTION_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user