8 changed files with 201 additions and 62 deletions
@ -0,0 +1,56 @@
|
||||
package com.logpm.factory.receiver; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
import com.logpm.factory.snm.entity.PanOrderStatusLog; |
||||
import com.logpm.factory.snm.service.IPanOrderStatusLogService; |
||||
import com.rabbitmq.client.Channel; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.common.constant.RabbitConstant; |
||||
import org.springframework.amqp.core.Message; |
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.Map; |
||||
|
||||
|
||||
/** |
||||
* 直接队列1 处理器 |
||||
* |
||||
* @author yangkai.shen |
||||
*/ |
||||
@Slf4j |
||||
@RabbitListener(queues = RabbitConstant.ERROR_QUEUE) |
||||
@Component |
||||
public class ErrorQueueHandler { |
||||
|
||||
@Autowired |
||||
private IPanOrderStatusLogService panOrderStatusLogService; |
||||
|
||||
@RabbitHandler |
||||
public void orderStatusHandlerManualAck(Map map, Message message, Channel channel) { |
||||
// 如果手动ACK,消息会被监听消费,但是消息在队列中依旧存在,如果 未配置 acknowledge-mode 默认是会在消费完毕后自动ACK掉
|
||||
final long deliveryTag = message.getMessageProperties().getDeliveryTag(); |
||||
try { |
||||
Long logId = (Long) map.get("logId"); |
||||
UpdateWrapper<PanOrderStatusLog> updateWrapper = new UpdateWrapper<>(); |
||||
updateWrapper.set("status",2) |
||||
.eq("id",logId); |
||||
boolean updateFlag = panOrderStatusLogService.update(updateWrapper); |
||||
if(updateFlag){ |
||||
channel.basicAck(deliveryTag, false); |
||||
}else{ |
||||
channel.basicReject(deliveryTag,true); |
||||
} |
||||
} catch (IOException e) { |
||||
try { |
||||
// 处理失败,重新压入MQ
|
||||
channel.basicReject(deliveryTag,true); |
||||
} catch (IOException e1) { |
||||
e1.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue