|
@@ -10,20 +10,27 @@ import com.usky.dxtop.common.utils.http.HttpUtils;
|
|
import com.usky.dxtop.model.Order;
|
|
import com.usky.dxtop.model.Order;
|
|
import com.usky.dxtop.service.OrderService;
|
|
import com.usky.dxtop.service.OrderService;
|
|
import com.usky.dxtop.service.api.TopApi;
|
|
import com.usky.dxtop.service.api.TopApi;
|
|
|
|
+import com.usky.dxtop.service.config.rabbiemq.CardConfig;
|
|
|
|
+import com.usky.dxtop.service.config.rabbiemq.PersonConfig;
|
|
import com.usky.dxtop.service.emun.OrderPayType;
|
|
import com.usky.dxtop.service.emun.OrderPayType;
|
|
import com.usky.dxtop.service.emun.OrderStatus;
|
|
import com.usky.dxtop.service.emun.OrderStatus;
|
|
import com.usky.dxtop.service.vo.CardLogsRequest;
|
|
import com.usky.dxtop.service.vo.CardLogsRequest;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.logging.log4j.core.util.JsonUtils;
|
|
import org.apache.logging.log4j.core.util.JsonUtils;
|
|
|
|
+import org.springframework.amqp.core.Message;
|
|
|
|
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.TreeMap;
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author yq
|
|
* @author yq
|
|
@@ -33,9 +40,75 @@ import java.util.TreeMap;
|
|
@RestController
|
|
@RestController
|
|
public class TestController {
|
|
public class TestController {
|
|
|
|
|
|
- @GetMapping("test1")
|
|
|
|
- public void test1(CardLogsRequest cardLogsRequest){
|
|
|
|
- System.out.println(cardLogsRequest);
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PersonConfig personConfig;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CardConfig cardConfig;
|
|
|
|
+
|
|
|
|
+ @GetMapping("/personTest")
|
|
|
|
+ public String sendDirectMessage() {
|
|
|
|
+ String messageId = String.valueOf(UUID.randomUUID());
|
|
|
|
+ String messageData = "test message, hello!";
|
|
|
|
+ String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
|
+ map.put("messageId",messageId);
|
|
|
|
+ map.put("messageData",messageData);
|
|
|
|
+ map.put("createTime",createTime);
|
|
|
|
+ //将消息携带绑定键值:TestDirectRouting 发送到交换机TestDirectExchange
|
|
|
|
+ personConfig.rabbitTemplate().convertAndSend(personConfig.getPersonExchange(), personConfig.getPersonRouteKey(), map);
|
|
|
|
+ return "ok";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/cartTest")
|
|
|
|
+ public String sendDirectMessageCard() {
|
|
|
|
+ String messageId = String.valueOf(UUID.randomUUID());
|
|
|
|
+ String messageData = "test message, hello!";
|
|
|
|
+ String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
|
+ map.put("messageId",messageId);
|
|
|
|
+ map.put("messageData",messageData);
|
|
|
|
+ map.put("createTime",createTime);
|
|
|
|
+ //将消息携带绑定键值:TestDirectRouting 发送到交换机TestDirectExchange
|
|
|
|
+ RabbitTemplate rabbitTemplate = cardConfig.rabbitTemplate();
|
|
|
|
+ cardConfig.rabbitTemplate().convertAndSend(cardConfig.getCardExchange(), cardConfig.getCardRouteKey(), map);
|
|
|
|
+ return "ok";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RabbitListener(queues = "profile_trans_produce", containerFactory = "personListenerFactory")
|
|
|
|
+ public void dealDeclareMessage(Message message) throws Exception {
|
|
|
|
+ try {
|
|
|
|
+ //消息类型
|
|
|
|
+ String routingKey = message.getMessageProperties().getReceivedRoutingKey();
|
|
|
|
+ log.info(routingKey);
|
|
|
|
+ //消息内容
|
|
|
|
+ String s = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
|
+ //处理你的消息
|
|
|
|
+ log.info("消息消费"+s);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("你的队列名"+"异常信息:" + e.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @RabbitListener(queues = "card_trans_produce", containerFactory = "cardListenerFactory")
|
|
|
|
+ public void dealDeclareMessageCart(Message message) throws Exception {
|
|
|
|
+ try {
|
|
|
|
+ //消息类型
|
|
|
|
+ String routingKey = message.getMessageProperties().getReceivedRoutingKey();
|
|
|
|
+ log.info(routingKey);
|
|
|
|
+ //消息内容
|
|
|
|
+ String s = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
|
+ //处理你的消息
|
|
|
|
+ log.info("消息消费"+s);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.info("你的队列名"+"异常信息:" + e.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|