|
@@ -2,9 +2,16 @@ package com.huimv.eartag2.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.huimv.eartag2.service.IDeviceService;
|
|
|
+import com.huimv.eartag2.service.RabbitMQService;
|
|
|
+import org.springframework.amqp.core.BindingBuilder;
|
|
|
+import org.springframework.amqp.core.DirectExchange;
|
|
|
+import org.springframework.amqp.core.Queue;
|
|
|
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
@@ -22,12 +29,39 @@ import java.util.UUID;
|
|
|
* @Create : 2020-12-25
|
|
|
**/
|
|
|
@RestController
|
|
|
+@RequestMapping
|
|
|
public class SendMessageController {
|
|
|
@Autowired
|
|
|
RabbitTemplate rabbitTemplate; //使用RabbitTemplate,这提供了接收/发送等等方法
|
|
|
@Autowired
|
|
|
private IDeviceService deviceService;
|
|
|
|
|
|
+ //动态创建队列
|
|
|
+// @Autowired
|
|
|
+// private RabbitMQService rabbitMQService;
|
|
|
+
|
|
|
+// @GetMapping("/sendDirectMessage2")
|
|
|
+// public void sendMessage(){
|
|
|
+//
|
|
|
+// rabbitMQService.createQueue("myDynamicQueue");
|
|
|
+//
|
|
|
+// // 创建交换机
|
|
|
+// rabbitMQService.createExchange("myDynamicExchange");
|
|
|
+//
|
|
|
+// // 创建绑定
|
|
|
+// rabbitMQService.createBinding("myDynamicQueue", "myDynamicExchange", "myRoutingKey");
|
|
|
+//
|
|
|
+//
|
|
|
+// rabbitTemplate.convertAndSend("myDynamicExchange", "myRoutingKey", "message");
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @RabbitListener(queues = "myDynamicQueue")
|
|
|
+// public void receiveMessage(String message) {
|
|
|
+// System.out.println("Received message: " + message);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/sendDirectMessage")
|
|
|
public String sendDirectMessage() {
|
|
|
String messageId = String.valueOf(java.util.UUID.randomUUID());
|