特邀发言官EG改为MQ

This commit is contained in:
lxu75
2025-06-17 14:37:43 +08:00
parent c6ade56f80
commit a50ca609de
3 changed files with 33 additions and 45 deletions

View File

@@ -1,27 +0,0 @@
package com.volvo.ai.analytic.center.controller;
import com.alibaba.fastjson.JSON;
import com.volvo.ai.analytic.center.service.SpokesManService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/community/event")
@Slf4j
public class CommunityEGEventController {
@Autowired
private SpokesManService spokesmanService;
@PostMapping("/spokesmanCallBack")
public void spokesmanCallBack(@RequestBody String req){
log.info("社区特邀发言官入参:{}", JSON.toJSONString(req));
spokesmanService.spokesManCallBack(req);
}
}

View File

@@ -0,0 +1,25 @@
package com.volvo.ai.analytic.center.mq;
import com.volvo.ai.analytic.center.service.SpokesManService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "${rocketmq.consumer.InvitedSpeaker.group}",
topic = "${rocketmq.consumer.InvitedSpeaker.topic}",
enableMsgTrace = true)
public class InvitedSpeakerConsumer implements RocketMQListener<MessageExt> {
@Autowired
private SpokesManService spokesmanService;
@Override
public void onMessage(MessageExt messageExt) {
log.info("特邀发言官 message: " + messageExt);
spokesmanService.spokesManCallBack(new String(messageExt.getBody()));
}
}

View File

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaweicloud.sdk.eg.v1.model.CloudEvents;
import com.volvo.ai.analytic.center.dto.req.DiFyReq;
import com.volvo.ai.analytic.center.dto.req.DifyImageWorkFlow;
import com.volvo.ai.analytic.center.dto.req.SpokesManDTO;
@@ -19,6 +18,7 @@ import com.volvo.ai.analytic.center.mapper.AiAnalyticBusinessConfigMapper;
import com.volvo.ai.analytic.center.utils.AiAnalysisUtils;
import com.volvo.ai.analytic.center.utils.PublishedTimeFormatter;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
@@ -41,23 +41,20 @@ public class SpokesManService {
@Autowired
private DiFyService diFyService;
@Autowired
private HuaWeiEGService huaWeiEGService;
@Autowired
private AiAnalysisRequestLogsMapper aiAnalysisRequestLogsMapper;
@Autowired
private AiAnalysisErrorsMapper aiAnalysisErrorsMapper;
@Autowired
private RocketMQTemplate rocketMQTemplate;
@Value("${dify.spokesMan.token}")
private String spokesManToken;
@Value("${huawei.cloud.EG.spokesMan.channelId}")
private String channelId;
@Value("${huawei.cloud.EG.spokesMan.sourceId}")
private String sourceId;
@Value("${rocketmq.producer.InvitedSpeaker.topic}")
private String topic;
/**
* 处理社区特邀发言官回调请求
@@ -117,15 +114,8 @@ public class SpokesManService {
difSpokesManResult.put("aiAnalysisRequestId", aiAnalysisRequestId);
//处理发布时间
updatePublishedTime(difSpokesManResult);
//发送事件网格
CloudEvents cloudEvents = new CloudEvents();
cloudEvents.setData(difSpokesManResult);
cloudEvents.setSource(sourceId);
cloudEvents.setSpecversion("1.0");
cloudEvents.setDatacontenttype("application/json");
cloudEvents.setType("SPOKESMAN");
cloudEvents.setId(aiAnalysisRequestId);
huaWeiEGService.sendEvent(cloudEvents, channelId);
//返回结果推送到社区的MQ
rocketMQTemplate.syncSend(topic, difSpokesManResult.toString());
//异步更新dify响应日志
syncUpdateDiFyResponse(difSpokesManResult, aiAnalysisRequestId);
} catch (Exception e) {