Commit e34111a4 authored by yanzg's avatar yanzg

消除成功接收处理

parent f6a5d469
package com.yanzuoguang.mq.service;
import com.rabbitmq.client.Channel;
import com.yanzuoguang.mq.vo.MessageVo;
import org.springframework.amqp.core.Message;
import java.util.List;
......@@ -48,4 +50,11 @@ public interface MessageService {
* @param messageVo
*/
String onError(MessageVo messageVo);
/**
* 消息收到确认
* @param message
* @param channel
*/
void basicAck(Message message, Channel channel);
}
package com.yanzuoguang.mq.service.impl;
import com.rabbitmq.client.Channel;
import com.yanzuoguang.mq.base.MyRabbitTemplate;
import com.yanzuoguang.mq.dao.MessageDao;
import com.yanzuoguang.mq.service.MessageService;
import com.yanzuoguang.mq.vo.MessageVo;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageDeliveryMode;
......@@ -16,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -137,7 +140,7 @@ public class MessageServiceImpl implements MessageService {
} else {
MessageVo messageTo = messageDao.load(messageVo.getMessageId(), MessageVo.class);
isEmpty = messageTo == null;
if(messageTo != null){
if (messageTo != null) {
messageVo = messageTo;
}
}
......@@ -156,4 +159,13 @@ public class MessageServiceImpl implements MessageService {
return messageVo.getMessageId();
}
@Override
public void basicAck(Message message, Channel channel) {
try {
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
} catch (IOException e) {
Log.error(MessageServiceImpl.class, e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment