|
@@ -0,0 +1,40 @@
|
|
|
+package com.persagy.apm.energyalarmstarter.alarmdata.mq;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmdata.mq.model.DmpMessage;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 将消息放入mq
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/10 9:45 上午
|
|
|
+ * @version: V1.0
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+public abstract class MessageSender {
|
|
|
+ @Value("${dmp.alarm.exchange}")
|
|
|
+ private String exchange;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RabbitTemplate rabbitTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 发送消息
|
|
|
+ * @param: message
|
|
|
+ * @param: routingKey
|
|
|
+ * @return: void
|
|
|
+ * @exception:
|
|
|
+ * @author: lixing
|
|
|
+ * @company: Persagy Technology Co.,Ltd
|
|
|
+ * @since: 2020/12/10 9:48 上午
|
|
|
+ * @version: V1.0
|
|
|
+ */
|
|
|
+ public void sendMessage(DmpMessage message, String routingKey) {
|
|
|
+ log.info("向rabbitMQ发送消息,message:" + JSONObject.toJSON(message).toString());
|
|
|
+ rabbitTemplate.convertAndSend(exchange, routingKey, JSONObject.toJSON(message).toString());
|
|
|
+ }
|
|
|
+}
|