|
@@ -22,6 +22,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import cn.afterturn.easypoi.word.WordExportUtil;
|
|
|
import com.backendsys.utils.MD5Util;
|
|
|
|
|
|
+import com.rabbitmq.client.Channel;
|
|
|
+import com.rabbitmq.client.GetResponse;
|
|
|
import com.tencentcloudapi.common.Credential;
|
|
|
//import io.github.pigmesh.ai.deepseek.core.DeepSeekClientImpl;
|
|
|
//import io.github.pigmesh.ai.deepseek.core.OpenAiHttpException;
|
|
@@ -32,11 +34,10 @@ import jakarta.annotation.PostConstruct;
|
|
|
import jakarta.servlet.ServletContext;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.redisson.api.*;
|
|
|
-import org.springframework.amqp.core.AmqpAdmin;
|
|
|
-import org.springframework.amqp.core.BindingBuilder;
|
|
|
-import org.springframework.amqp.core.DirectExchange;
|
|
|
+import org.springframework.amqp.core.*;
|
|
|
import org.springframework.amqp.core.Queue;
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
+import org.springframework.amqp.rabbit.connection.Connection;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -48,6 +49,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.awt.*;
|
|
|
import java.io.*;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
@@ -56,21 +58,6 @@ import java.util.List;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
-
|
|
|
-//import com.tencentcloudapi.facefusion.v20181201.FacefusionClient;
|
|
|
-//import com.tencentcloudapi.facefusion.v20181201.models.*;
|
|
|
-
|
|
|
-//import com.tencentcloudapi.facefusion.v20220927.FacefusionClient;
|
|
|
-//import com.tencentcloudapi.facefusion.v20220927.models.*;
|
|
|
-
|
|
|
-//import com.tencentcloudapi.common.Credential;
|
|
|
-//import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
-//import com.tencentcloudapi.common.profile.HttpProfile;
|
|
|
-//import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
-//import com.tencentcloudapi.facefusion.v20181201.FacefusionClient;
|
|
|
-//import com.tencentcloudapi.facefusion.v20181201.models.*;
|
|
|
-
|
|
|
-
|
|
|
import com.tencentcloudapi.common.CommonClient;
|
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
|
|
@@ -86,22 +73,24 @@ public class TestController {
|
|
|
@Value("${tencent.facefusion.secret-key}")
|
|
|
private String SECRET_KEY;
|
|
|
|
|
|
- @Autowired
|
|
|
- private AmqpAdmin amqpAdmin;
|
|
|
+// @Autowired
|
|
|
+// private AmqpAdmin amqpAdmin;
|
|
|
@Autowired
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
- private void initRabbitMQ() {
|
|
|
- System.out.println("-- initRabbitMQ. --");
|
|
|
+// private void initRabbitMQ() {
|
|
|
+// System.out.println("-- initRabbitMQ. --");
|
|
|
+//
|
|
|
// // 交换机
|
|
|
// amqpAdmin.declareExchange(new DirectExchange("demo.exchange", true, false));
|
|
|
//
|
|
|
-//// Map<String, Object> args = new HashMap<>();
|
|
|
-//// args.put("x-message-ttl", 5000); // 消息 TTL:60 秒(单位毫秒)
|
|
|
-//// // 队列
|
|
|
-//// amqpAdmin.declareQueue(new Queue("demo.queue", true, false, false, args));
|
|
|
+// // 队列 (TTL + 死信)
|
|
|
+// Map<String, Object> args = new HashMap<>();
|
|
|
+// args.put("x-message-ttl", 5000); // 消息 TTL:60 秒(单位毫秒)
|
|
|
+// amqpAdmin.declareQueue(new Queue("demo.queue", true, false, false, args));
|
|
|
//
|
|
|
-// amqpAdmin.declareQueue(new Queue("demo.queue", true));
|
|
|
+//// // 队列
|
|
|
+//// amqpAdmin.declareQueue(new Queue("demo.queue", true));
|
|
|
//
|
|
|
// // 把队列 demo.queue 绑定到交换机 demo.exchange,路由键设置为 order.create
|
|
|
// amqpAdmin.declareBinding(
|
|
@@ -110,39 +99,64 @@ public class TestController {
|
|
|
// .with("order.create")
|
|
|
// );
|
|
|
|
|
|
- // 单队列 (无死信)
|
|
|
- amqpAdmin.declareQueue(new Queue("demo.queue", true));
|
|
|
- }
|
|
|
+// // 单队列 (无死信)
|
|
|
+// amqpAdmin.declareQueue(new Queue("demo.queue", true));
|
|
|
+// }
|
|
|
|
|
|
@GetMapping("/testRabbitMQ/send")
|
|
|
public String send() {
|
|
|
- initRabbitMQ();
|
|
|
+
|
|
|
+// initRabbitMQ();
|
|
|
// rabbitTemplate.convertAndSend("demo.exchange", "order.create", "Hello RabbitMQ!");
|
|
|
// rabbitTemplate.convertAndSend("", "demo.queue", "Hello RabbitMQ!");
|
|
|
|
|
|
SysUser sysUser = new SysUser();
|
|
|
- sysUser.setId(1L);
|
|
|
+ sysUser.setUsername(UUID.randomUUID().toString());
|
|
|
+ System.out.println("【发送】:" + sysUser);
|
|
|
// rabbitTemplate.convertAndSend("", "demo.queue", sysUser);
|
|
|
- rabbitTemplate.convertAndSend("demo.exchange", "order.create", sysUser);
|
|
|
+ rabbitTemplate.convertAndSend("order.exchange", "order.create", sysUser);
|
|
|
+
|
|
|
return "ok";
|
|
|
}
|
|
|
|
|
|
- @PostConstruct
|
|
|
- public void init() {
|
|
|
- rabbitTemplate.setConfirmCallback((corData, ack, cause) -> {
|
|
|
- if (!ack) {
|
|
|
- System.out.println("消息发送失败:" + corData + ",原因:" + cause);
|
|
|
- }
|
|
|
- });
|
|
|
- rabbitTemplate.setReturnsCallback(ret -> {
|
|
|
- System.out.println("消息无法路由到队列:" + ret.getMessage());
|
|
|
- });
|
|
|
+ @GetMapping("/testRabbitMQ/poll")
|
|
|
+ public String poll() throws Exception {
|
|
|
+
|
|
|
+ // 1. 拿到连接和 channel(不要每次 new)
|
|
|
+ Connection connection = rabbitTemplate.getConnectionFactory().createConnection();
|
|
|
+ Channel channel = connection.createChannel(false);
|
|
|
+
|
|
|
+ // 2. 手动拉消息,第二个参数传 false 表示“不要自动 ack”
|
|
|
+ GetResponse resp = channel.basicGet("order.queue", false);
|
|
|
+ if (resp == null) {
|
|
|
+ channel.close();
|
|
|
+ connection.close();
|
|
|
+ return "no message";
|
|
|
+ }
|
|
|
+
|
|
|
+ String body = new String(resp.getBody(), StandardCharsets.UTF_8);
|
|
|
+ System.out.println("手动处理完:" + body);
|
|
|
+
|
|
|
+ // 3. 用同一个 channel 去 ack
|
|
|
+ channel.basicAck(resp.getEnvelope().getDeliveryTag(), false);
|
|
|
+ channel.close();
|
|
|
+ connection.close();
|
|
|
+ return "acked: " + body;
|
|
|
+
|
|
|
+
|
|
|
+// try {
|
|
|
+// channel.basicAck(msg.getMessageProperties().getDeliveryTag(), false);
|
|
|
+// } finally {
|
|
|
+// channel.close();
|
|
|
+// }
|
|
|
+// return "acked: " + body;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// @Autowired
|
|
|
// private DeepSeekClientImpl deepSeekClient;
|
|
|
//
|