From 09d010da12e5dd22766cf0979f8f34c968ab6ffd Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期二, 10 九月 2024 11:39:36 +0800 Subject: [PATCH] mq修改 --- ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduce.java | 74 +++++++++++++++++++++--------------- 1 files changed, 43 insertions(+), 31 deletions(-) diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduce.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduce.java index 5586e13..762cdbd 100644 --- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduce.java +++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/rocket/produce/EnhanceProduce.java @@ -7,11 +7,12 @@ import com.ruoyi.integration.rocket.util.RocketMQEnhanceTemplate; import lombok.Setter; import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.remoting.common.RemotingHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import java.util.UUID; @@ -23,7 +24,7 @@ @Setter(onMethod_ = @Autowired) private RocketMQEnhanceTemplate rocketMQEnhanceTemplate; - private static final String TOPIC = "rocket_enhance"; + private static final String TOPIC = "charge_"; /** * 充电桩登录认证 @@ -34,7 +35,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.ONLINE); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.ONLINE, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.ONLINE, SendTagConstant.ONLINE, message); } /** @@ -46,7 +47,18 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.PING); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PING, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.PING, SendTagConstant.PING, message); + } + /** + * 充电结束 + */ + public SendResult endChargeMessage(JSONObject jsonObject) { + PingMessage message = JSON.parseObject(jsonObject.toJSONString(),PingMessage.class); + // 设置业务key + message.setKey(UUID.randomUUID().toString()); + // 设置消息来源,便于查询 + message.setSource(SendTagConstant.END_CHARGE); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.END_CHARGE, SendTagConstant.END_CHARGE, message); } /** @@ -58,7 +70,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.BILLING_MODE_VERIFY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BILLING_MODE_VERIFY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.BILLING_MODE_VERIFY, SendTagConstant.BILLING_MODE_VERIFY, message); } /** @@ -70,7 +82,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.ACQUISITION_BILLING_MODE); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.ACQUISITION_BILLING_MODE, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.ACQUISITION_BILLING_MODE, SendTagConstant.ACQUISITION_BILLING_MODE, message); } /** @@ -82,7 +94,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA, SendTagConstant.UPLOAD_REAL_TIME_MONITORING_DATA, message); } /** @@ -94,7 +106,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.CHARGING_HANDSHAKE); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_HANDSHAKE, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.CHARGING_HANDSHAKE, SendTagConstant.CHARGING_HANDSHAKE, message); } /** @@ -106,7 +118,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.BMS_ABORT); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_ABORT, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.BMS_ABORT, SendTagConstant.BMS_ABORT, message); } /** @@ -118,7 +130,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.MOTOR_ABORT); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.MOTOR_ABORT, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.MOTOR_ABORT, SendTagConstant.MOTOR_ABORT, message); } /** @@ -130,7 +142,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION, SendTagConstant.BMS_DEMAND_AND_CHARGER_EXPORTATION, message); } /** @@ -142,7 +154,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.BMS_INFORMATION); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.BMS_INFORMATION, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.BMS_INFORMATION, SendTagConstant.BMS_INFORMATION, message); } /** @@ -154,7 +166,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.CHARGING_PILE_STARTS_CHARGING); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_PILE_STARTS_CHARGING, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.CHARGING_PILE_STARTS_CHARGING, SendTagConstant.CHARGING_PILE_STARTS_CHARGING, message); } /** @@ -166,7 +178,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.PLATFORM_START_CHARGING_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_START_CHARGING_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.PLATFORM_START_CHARGING_REPLY, SendTagConstant.PLATFORM_START_CHARGING_REPLY, message); } /** @@ -178,7 +190,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.PLATFORM_STOP_CHARGING_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_STOP_CHARGING_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.PLATFORM_STOP_CHARGING_REPLY, SendTagConstant.PLATFORM_STOP_CHARGING_REPLY, message); } /** @@ -190,7 +202,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.TRANSACTION_RECORD); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.TRANSACTION_RECORD, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.TRANSACTION_RECORD, SendTagConstant.TRANSACTION_RECORD, message); } /** @@ -202,7 +214,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.UPDATE_BALANCE_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.UPDATE_BALANCE_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.UPDATE_BALANCE_REPLY, SendTagConstant.UPDATE_BALANCE_REPLY, message); } /** @@ -214,7 +226,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY, SendTagConstant.SYNCHRONIZE_OFFLINE_CARD_REPLY, message); } /** @@ -226,7 +238,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.CLEAR_OFFLINE_CARD_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CLEAR_OFFLINE_CARD_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.CLEAR_OFFLINE_CARD_REPLY, SendTagConstant.CLEAR_OFFLINE_CARD_REPLY, message); } /** @@ -238,19 +250,19 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.WORKING_PARAMETER_SETTING_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.WORKING_PARAMETER_SETTING_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.WORKING_PARAMETER_SETTING_REPLY, SendTagConstant.WORKING_PARAMETER_SETTING_REPLY, message); } /** - * 对时设置应答 + * 对时设置 */ - public SendResult timingSettingReplyMessage(JSONObject jsonObject) { - TimingSettingReplyMessage message = JSON.parseObject(jsonObject.toJSONString(),TimingSettingReplyMessage.class); + public SendResult timingSettingMessage(JSONObject jsonObject) { + TimingSettingMessage message = JSON.parseObject(jsonObject.toJSONString(),TimingSettingMessage.class); // 设置业务key message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 - message.setSource(SendTagConstant.TIMING_SETTING_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.TIMING_SETTING_REPLY, message); + message.setSource(SendTagConstant.TIMING_SETTING); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.TIMING_SETTING, SendTagConstant.TIMING_SETTING, message); } /** @@ -262,7 +274,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.SETUP_BILLING_MODEL_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.SETUP_BILLING_MODEL_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.SETUP_BILLING_MODEL_REPLY, SendTagConstant.SETUP_BILLING_MODEL_REPLY, message); } /** @@ -274,7 +286,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.GROUND_LOCK_REAL_TIME_DATA); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.GROUND_LOCK_REAL_TIME_DATA, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.GROUND_LOCK_REAL_TIME_DATA, SendTagConstant.GROUND_LOCK_REAL_TIME_DATA, message); } /** @@ -286,7 +298,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA, SendTagConstant.CHARGING_PILE_RETURNS_GROUND_LOCK_DATA, message); } /** @@ -298,7 +310,7 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.PLATFORM_RESTART_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_RESTART_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.PLATFORM_RESTART_REPLY, SendTagConstant.PLATFORM_RESTART_REPLY, message); } /** @@ -310,6 +322,6 @@ message.setKey(UUID.randomUUID().toString()); // 设置消息来源,便于查询 message.setSource(SendTagConstant.PLATFORM_REMOTE_UPDATE_REPLY); - return rocketMQEnhanceTemplate.send(TOPIC, SendTagConstant.PLATFORM_REMOTE_UPDATE_REPLY, message); + return rocketMQEnhanceTemplate.send(TOPIC+SendTagConstant.PLATFORM_REMOTE_UPDATE_REPLY, SendTagConstant.PLATFORM_REMOTE_UPDATE_REPLY, message); } } \ No newline at end of file -- Gitblit v1.7.1