Browse Source

Merge remote-tracking branch 'origin/dev' into dev

dist.1.3.0
pref_mail@163.com 9 months ago
parent
commit
d0c2f38666
  1. 22
      blade-service/logpm-factory-data/logpm-factory-data-base/src/main/java/com/logpm/factorydata/base/service/impl/MqServiceImpl.java

22
blade-service/logpm-factory-data/logpm-factory-data-base/src/main/java/com/logpm/factorydata/base/service/impl/MqServiceImpl.java

@ -11,17 +11,24 @@ import com.logpm.factorydata.base.exception.MsgException;
import com.logpm.factorydata.base.service.FailMsgService;
import com.logpm.factorydata.base.service.MqService;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* @author zhaoqiaobo
@ -97,6 +104,21 @@ public class MqServiceImpl implements MqService {
try {
// 5.发送消息
this.rabbitTemplate.convertAndSend(exchange, routingKey, message, messagePostProcessor -> {
HttpHeaders headers = (HttpHeaders) ThreadLocalUtil.get("bladeContext");
if (headers != null && !headers.isEmpty()) {
headers.forEach((key, values) -> {
values.forEach((value) -> {
messagePostProcessor.getMessageProperties().setHeader(key, new String[]{value});
});
});
}
BladeUser user = AuthUtil.getUser();
BladeUser bladeUser = new BladeUser();
bladeUser.setTenantId(user.getTenantId());
bladeUser.setUserId(user.getUserId());
bladeUser.setAccount(user.getAccount());
bladeUser.setRoleId(user.getRoleId());
messagePostProcessor.getMessageProperties().setHeader("bladeUser", JSONUtil.toJsonStr(bladeUser));
//设置延时发送时间,delay小于0,实时发送
messagePostProcessor.getMessageProperties().setDelay(delay);
return messagePostProcessor;

Loading…
Cancel
Save