- 监听文件类
import cn.hutool.json.JSONObject;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import jnpf.util.JsonUtil;
import jzy.model.mom.EventMessageMom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.io.IOException;@Component
@ConditionalOnProperty(name = "spring.rabbitmq.enable", havingValue = "true", matchIfMissing = true)
public class MultiExchangeMessageListener{private static final Logger logger = LoggerFactory.getLogger(MultiExchangeMessageListener.class);@Autowiredprivate IdempotentMessageProcessor idempotentProcessor;@Autowiredprivate RabbitTemplate rabbitTemplate;@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "order.queue", durable = "true"), exchange = @Exchange(name = "20250917test1", type = ExchangeTypes.FANOUT) ))public void handleMessage(Message message) throws IOException {String messageId = message.getMessageProperties().getMessageId();String exchange = message.getMessageProperties().getReceivedExchange();long deliveryTag = message.getMessageProperties().getDeliveryTag();}
- 配置文件:在yml里配置具体开关的属性,配置rabbitMq启用开关,false为关闭,true为启用.
spring:rabbitmq:addresses: 127.0.0.1:5672username: guestpassword: guestvirtual-host: /connection-timeout: 15000enable: truelistener:simple:acknowledge-mode: manualconcurrency: 15max-concurrency: 20