|
@@ -1,7 +1,6 @@
|
|
|
package com.persagy.dc.amqp.handler;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -28,21 +27,36 @@ public class RabbitMessageSender {
|
|
|
private Set<String> disableKeys;
|
|
|
|
|
|
/**
|
|
|
- * 发送消息
|
|
|
+ * 发送异步消息
|
|
|
* @param exchange 发送的交换机
|
|
|
* @param routingKey 路由Key
|
|
|
- * @param message
|
|
|
+ * @param message 消息体
|
|
|
*/
|
|
|
public void send(String exchange, String routingKey, String message) {
|
|
|
log.info("开始发送消息,routingKey={},message={}", routingKey, message);
|
|
|
// 配置了不发此类消息
|
|
|
- if(CollUtil.isNotEmpty(disableKeys) &&
|
|
|
- StrUtil.isNotBlank(routingKey) &&
|
|
|
- disableKeys.contains(routingKey)) {
|
|
|
+ if(CollUtil.contains(disableKeys, routingKey)) {
|
|
|
return;
|
|
|
}
|
|
|
// 发送 异常不捕获直接抛出
|
|
|
rabbitTemplate.convertAndSend(exchange, routingKey, message);
|
|
|
log.info("消息发送成功,routingKey={}", routingKey);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送同步消息
|
|
|
+ * @param exchange 发送的交换机
|
|
|
+ * @param routingKey 路由Key
|
|
|
+ * @param message 消息体
|
|
|
+ */
|
|
|
+ public void sendAndReceive(String exchange, String routingKey, String message) {
|
|
|
+ log.info("开始发送消息,routingKey={},message={}", routingKey, message);
|
|
|
+ // 配置了不发此类消息
|
|
|
+ if(CollUtil.contains(disableKeys, routingKey)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 发送 异常不捕获直接抛出
|
|
|
+ rabbitTemplate.convertSendAndReceive(exchange, routingKey, message);
|
|
|
+ log.info("消息发送成功,routingKey={}", routingKey);
|
|
|
+ }
|
|
|
}
|