This commit is contained in:
Mauve
2026-09-08 15:12:29 +08:00
commit 078ba3c713
672 changed files with 56677 additions and 0 deletions
@@ -0,0 +1,47 @@
package com.mgm.mcrm.common.jms;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson2.JSON;
import com.mgm.mcrm.common.dtos.msg.JMSTextMessage;
import com.mgm.mcrm.common.utils.LogUtil;
@Component
public class AppControlMsgSender {
@Value("${app_ctrl_topic}")
private String ctrlTopicName;
private ActiveMQTopic ctrlTopic=null;
@Autowired
private JmsTemplate jmsTemplate;
private ActiveMQTopic getTopic() {
return this.ctrlTopic==null?new ActiveMQTopic(ctrlTopicName):this.ctrlTopic;
}
public void sendMessage(String message) {
jmsTemplate.convertAndSend(getTopic(), message);
}
public boolean sendMessage(String msgType, Object msgData) {
boolean result =false;
try {
JMSTextMessage msg = new JMSTextMessage();
msg.setMsgType(msgType);
msg.setMsgContent(msgData==null?"":JSON.toJSONString(msgData));
String message = JSON.toJSONString(msg);
jmsTemplate.convertAndSend(getTopic(), message);
result=true;
}catch(Exception err) {
LogUtil.error(AppControlMsgSender.class, "Send JMS Failed:"+err.getMessage());
result=false;
}
return result;
}
}