dsx 2 лет назад
Родитель
Сommit
887ac6b756

+ 20 - 0
src/main/java/com/fdkankan/openApi/controller/TestController.java

@@ -12,6 +12,7 @@ import com.fdkankan.openApi.service.system.IAccountService;
 import com.fdkankan.openApi.service.system.IUserAuthInfoService;
 import com.fdkankan.openApi.service.system.IUserAuthInfoService;
 import com.fdkankan.openApi.service.www.IUserService;
 import com.fdkankan.openApi.service.www.IUserService;
 import com.fdkankan.openApi.util.TokenUtil;
 import com.fdkankan.openApi.util.TokenUtil;
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
 import com.fdkankan.web.controller.BaseController;
 import com.fdkankan.web.controller.BaseController;
 import com.fdkankan.web.response.ResultData;
 import com.fdkankan.web.response.ResultData;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +21,9 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
 /**
  * @author Xiewj
  * @author Xiewj
  * @date 2023/2/9
  * @date 2023/2/9
@@ -40,6 +44,8 @@ public class TestController extends BaseController {
     private LocalOverCache localOverCache;
     private LocalOverCache localOverCache;
     @Autowired
     @Autowired
     private IUserService userService;
     private IUserService userService;
+    @Autowired
+    private RabbitMqProducer rabbitMqProducer;
 
 
 
 
     @GetMapping("/test")
     @GetMapping("/test")
@@ -59,4 +65,18 @@ public class TestController extends BaseController {
         return ResultData.ok("ok");
         return ResultData.ok("ok");
     }
     }
 
 
+//    @GetMapping("testMQPriority")
+//    @SaIgnore
+//    public ResultData testMQPriority() throws InterruptedException {
+//
+//        for(int i = 1; i <= 10; i++){
+//            Map<String, Integer> map = new HashMap<>();
+//            map.put("val", i);
+//            rabbitMqProducer.sendByWorkQueue("test_priority", map);
+//            Thread.sleep(2000);
+//        }
+//
+//        return ResultData.ok("ok");
+//    }
+
 }
 }

+ 13 - 0
src/main/java/com/fdkankan/openApi/mq/listener/CallApiListener.java

@@ -7,6 +7,7 @@ import com.fdkankan.openApi.service.system.IUserAuthInfoService;
 import com.rabbitmq.client.Channel;
 import com.rabbitmq.client.Channel;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.core.Message;
 import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Argument;
 import org.springframework.amqp.rabbit.annotation.Queue;
 import org.springframework.amqp.rabbit.annotation.Queue;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -64,4 +65,16 @@ public class CallApiListener {
             e.printStackTrace();
             e.printStackTrace();
         }
         }
     }
     }
+
+//    @RabbitListener(
+//            queuesToDeclare = @Queue(name = "test_priority", arguments = {@Argument(name = "x-max-priority", value = "30", type = "java.lang.Integer")}),
+//            concurrency = "1"
+//    )
+//    public void priority(Channel channel, Message message) throws Exception {
+//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
+//        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+//        String messageId = message.getMessageProperties().getMessageId();
+//        System.out.println(msg);
+//        channel.basicAck(deliveryTag, false);
+//    }
 }
 }