Commit e3f38cad authored by yanzg's avatar yanzg

修改实例化关系

parent b04da154
......@@ -1007,6 +1007,18 @@ public class StringHelper {
return getMD5Id(froms);
}
/**
* 获取组合编号
*
* @param args 需要组合的编号
* @return 将ID列表进行组合生成ID
*/
public static String getIdShort(String from, Object... args) {
String id = getId(args);
return from.replaceFirst(id, "");
}
/**
* 获取组合编号
*
......
......@@ -77,12 +77,11 @@ public class MessageSendServiceImpl implements MessageSendService {
@Override
public String send(MessageVo req) {
req.check();
// 获取消息临时Id
// 获取消息临时Id,消息Id为空时标识为第一次发送,并设置默认消息Id
String finalMessageId = StringHelper.getFirst(req.getMessageId(), StringHelper.getId("temp", StringHelper.getNewID()));
// 设置编号
CorrelationData correlationData = new CorrelationData();
correlationData.setId(finalMessageId);
rabbitTemplate.getRabbitTemplate().convertAndSend(req.getExchangeName(), req.getRouteKey(), req.getMessage(), new MessagePostProcessor() {
@Override
public Message postProcessMessage(Message message) throws AmqpException {
......@@ -91,8 +90,7 @@ public class MessageSendServiceImpl implements MessageSendService {
// 设置持久化
properties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
// 设置消息编号
properties.setMessageId(finalMessageId);
properties.setMessageId(StringHelper.getIdShort(finalMessageId, "temp"));
if (req.getDedTime() > 0) {
properties.setExpiration(req.getDedTime() + "");
}
......
......@@ -6,6 +6,7 @@ import com.yanzuoguang.mq.service.*;
import com.yanzuoguang.mq.vo.MessageVo;
import com.yanzuoguang.mq.vo.QueueVo;
import com.yanzuoguang.mq.vo.req.*;
import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
......@@ -67,6 +68,13 @@ public class MqServiceImpl implements MqService {
@Override
public String message(MessageVo req, boolean now) {
req.check();
// 设置默认消息Id
String defaultId = StringHelper.getFirst(req.getMessageId(), StringHelper.getNewID());
// 将Id去掉temp:
String simpleId = StringHelper.getIdShort(defaultId, "temp");
// 增加temp标识第一次发送
req.setMessageId(StringHelper.getId("temp", simpleId));
return yzgMqProcedure.send(req, now);
}
......
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