From 435c57034e7748b0cad522e263350d14bf592315 Mon Sep 17 00:00:00 2001 From: caixiang <939387484@qq.com> Date: Tue, 15 Nov 2022 16:09:08 +0800 Subject: [PATCH] mark --- .../qgs/dc/mq/consumer/PID10_1Received.java | 29 +++++++++++++++++-- .../com/qgs/dc/mq/consumer/PID18Received.java | 1 + .../com/qgs/dc/mq/consumer/PID4BReceived.java | 1 + .../java/com/qgs/dc/mq/entity/MQMessage.java | 5 +++- .../com/qgs/dc/mq/entity/common/Returns.java | 25 ++++------------ .../mq/producer/component/RabbitSender.java | 8 +++-- 6 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/qgs/dc/mq/consumer/PID10_1Received.java b/src/main/java/com/qgs/dc/mq/consumer/PID10_1Received.java index f695ef8..fa40a7b 100644 --- a/src/main/java/com/qgs/dc/mq/consumer/PID10_1Received.java +++ b/src/main/java/com/qgs/dc/mq/consumer/PID10_1Received.java @@ -9,8 +9,11 @@ import com.qgs.dc.mq.configuration.ConfigOfPID10_1; import com.qgs.dc.mq.consumer.commonHandler.MQMessageHandler; import com.qgs.dc.mq.entity.MQMessage; import com.qgs.dc.mq.entity.common.Header; +import com.qgs.dc.mq.entity.common.Returns; import com.qgs.dc.mq.entity.specificBody.QueryEQStatusBody; +import com.qgs.dc.mq.producer.component.RabbitSender; import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Return; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.amqp.rabbit.annotation.RabbitHandler; @@ -32,11 +35,12 @@ import java.util.List; * Ctrl+R 替换设备名 */ @Component -public class PID10_1Received { +public class PID10_1Received{ private static final Logger logger = LoggerFactory.getLogger(PID10_1Received.class); - + @Autowired + RabbitSender rabbitSender; @Autowired MQMessageHandler mqMessageHandler; @@ -59,6 +63,9 @@ public class PID10_1Received { System.out.println("收到的消息是: "+mqMessage.toString()); System.out.println(); logger.info(mqMessage.toString()); + //todo reply + reply(mqMessage); + channel.basicAck(deliveryTag,false); System.out.println(mqMessage.toString()); }catch (Exception e){ @@ -70,6 +77,24 @@ public class PID10_1Received { } + public void reply(MQMessage request) throws Exception { + MQMessage response = new MQMessage(); + + Header header = request.getHeader(); + header.setFrom("mes"); + header.setTo("eap"); + header.setMessageType("Response"); + header.setSendTimestamp(CommonFunction.getNowDate(1)); + Returns aReturn = new Returns("0","0"); + + response.setHeader(header); + response.setReturns(aReturn); + + rabbitSender.sendDirect(response,ConfigOfPID10_1.EXCHANGE_NAME_PID10_1,ConfigOfPID10_1.EAP_RESPONSE_QUEUE_ROUTINGKEY_PID10_1); + System.out.println("reply: "+response.toString()); + } + + // @RabbitListener(queues = ConfigOfPID10_1.MES_REQUEST_QUEUE_PID10_1) // @RabbitHandler diff --git a/src/main/java/com/qgs/dc/mq/consumer/PID18Received.java b/src/main/java/com/qgs/dc/mq/consumer/PID18Received.java index f973166..b726ec2 100644 --- a/src/main/java/com/qgs/dc/mq/consumer/PID18Received.java +++ b/src/main/java/com/qgs/dc/mq/consumer/PID18Received.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.qgs.dc.common.utils.CommonFunction; import com.qgs.dc.mq.Constant.Constant; +import com.qgs.dc.mq.configuration.ConfigOfPID13S; import com.qgs.dc.mq.configuration.ConfigOfPID18; import com.qgs.dc.mq.consumer.commonHandler.MQMessageHandler; import com.qgs.dc.mq.entity.MQMessage; diff --git a/src/main/java/com/qgs/dc/mq/consumer/PID4BReceived.java b/src/main/java/com/qgs/dc/mq/consumer/PID4BReceived.java index 4406ba0..a30205c 100644 --- a/src/main/java/com/qgs/dc/mq/consumer/PID4BReceived.java +++ b/src/main/java/com/qgs/dc/mq/consumer/PID4BReceived.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.qgs.dc.common.utils.CommonFunction; import com.qgs.dc.mq.Constant.Constant; +import com.qgs.dc.mq.configuration.ConfigOfPID13S; import com.qgs.dc.mq.configuration.ConfigOfPID4B; import com.qgs.dc.mq.consumer.commonHandler.MQMessageHandler; import com.qgs.dc.mq.entity.MQMessage; diff --git a/src/main/java/com/qgs/dc/mq/entity/MQMessage.java b/src/main/java/com/qgs/dc/mq/entity/MQMessage.java index c4ff78b..34a0817 100644 --- a/src/main/java/com/qgs/dc/mq/entity/MQMessage.java +++ b/src/main/java/com/qgs/dc/mq/entity/MQMessage.java @@ -15,10 +15,13 @@ import java.util.HashMap; * @DATE: 2021/8/12 15:38 */ @Data -@JSONType(orders={"header","body","returns"}) +@JSONType(orders={"header","body","return"}) public class MQMessage { private Header header; @JSONField(jsonDirect = true) private String body; + @JSONField(name = "return") private Returns returns; + + } \ No newline at end of file diff --git a/src/main/java/com/qgs/dc/mq/entity/common/Returns.java b/src/main/java/com/qgs/dc/mq/entity/common/Returns.java index 4d48826..247889d 100644 --- a/src/main/java/com/qgs/dc/mq/entity/common/Returns.java +++ b/src/main/java/com/qgs/dc/mq/entity/common/Returns.java @@ -1,5 +1,6 @@ package com.qgs.dc.mq.entity.common; +import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; import lombok.Data; @@ -9,29 +10,15 @@ import lombok.Data; * @DATE: 2021/8/12 15:35 */ @Data -@JSONType(orders={"returnCode","ReasonCode"}) +@JSONType(orders={"ReturnCode","ReasonCode"}) public class Returns { - private String returnCode; + @JSONField(name = "ReturnCode") + private String ReturnCode; + @JSONField(name = "ReasonCode") private String ReasonCode; - public String getReturnCode() { - return returnCode; - } - - public void setReturnCode(String returnCode) { - this.returnCode = returnCode; - } - - public String getReasonCode() { - return ReasonCode; - } - - public void setReasonCode(String reasonCode) { - ReasonCode = reasonCode; - } - public Returns(String returnCode, String reasonCode) { - this.returnCode = returnCode; + ReturnCode = returnCode; ReasonCode = reasonCode; } } diff --git a/src/main/java/com/qgs/dc/mq/producer/component/RabbitSender.java b/src/main/java/com/qgs/dc/mq/producer/component/RabbitSender.java index 82fe11e..07c4454 100644 --- a/src/main/java/com/qgs/dc/mq/producer/component/RabbitSender.java +++ b/src/main/java/com/qgs/dc/mq/producer/component/RabbitSender.java @@ -3,6 +3,8 @@ package com.qgs.dc.mq.producer.component; import com.alibaba.fastjson.JSONObject; import com.qgs.dc.common.utils.CommonFunction; import com.qgs.dc.mq.entity.MQMessage; +import com.qgs.dc.mq.entity.common.Header; +import com.qgs.dc.mq.entity.common.Returns; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,6 +19,7 @@ import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.MessageBuilder; import org.springframework.stereotype.Component; +import java.sql.SQLOutput; import java.util.Map; import java.util.Random; import java.util.UUID; @@ -190,12 +193,13 @@ public class RabbitSender { cd ); } + + + public void sendDirect(MQMessage mqMessage, String exchange, String routingKey) throws Exception{ - System.out.println("(before)mqMessage: "+mqMessage.toString()); byte[] message = JSONObject.toJSONBytes(mqMessage); - System.out.println("(after)mqMessage: "+new String(message)); String transitionId = mqMessage.getHeader().getTransactionId(); CorrelationData cd = new CorrelationData(transitionId); rabbitTemplate.setConfirmCallback(confirmCallback);