You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
2 years ago
|
package com.glxp.api.service.trace;
|
||
|
|
||
|
import cn.hutool.core.lang.UUID;
|
||
|
import com.glxp.api.common.res.BaseResponse;
|
||
|
import com.glxp.api.common.util.ResultVOUtils;
|
||
|
import com.glxp.api.config.rabbit.TopicRabbitConfig;
|
||
|
import com.glxp.api.entity.trace.MqTraceMessage;
|
||
|
import com.glxp.api.util.DateUtil;
|
||
|
import lombok.RequiredArgsConstructor;
|
||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||
|
import org.springframework.stereotype.Service;
|
||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||
|
|
||
|
import javax.annotation.Resource;
|
||
|
import java.util.Date;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
@Service
|
||
|
@RequiredArgsConstructor
|
||
|
public class RabbitPushService {
|
||
|
|
||
|
@Resource
|
||
|
private final RabbitTemplate rabbitTemplate;
|
||
|
|
||
|
public BaseResponse send(MqTraceMessage mqTraceMessage) {
|
||
|
rabbitTemplate.convertAndSend("topicExchange", TopicRabbitConfig.trace, mqTraceMessage);
|
||
|
return ResultVOUtils.success("发送成功");
|
||
|
}
|
||
|
|
||
|
public BaseResponse sendCommon(String key) {
|
||
|
String messageId = String.valueOf(UUID.randomUUID());
|
||
|
Map<String, Object> messageMap = new HashMap<>();
|
||
|
messageMap.put("messageId", messageId);
|
||
|
messageMap.put("messageData", key);
|
||
|
messageMap.put("createTime", DateUtil.formatDate(new Date()));
|
||
|
rabbitTemplate.convertAndSend("topicExchange", TopicRabbitConfig.common, messageMap);
|
||
|
return ResultVOUtils.success("发送成功");
|
||
|
}
|
||
|
}
|