Spring AMQP 可以轻松集成 RabbitMQ,实现消息异步处理。通过在 Spring Boot 配置文件中指定 spring.rabbitmq.host、port、username、password,再使用 RabbitTemplate 发送消息即可:
rabbitTemplate.convertAndSend("exchange", "routingKey", message);
消费者通过 @RabbitListener 注解监听队列,实现消息消费。注意 RabbitMQ 默认 guest 用户只能本机登录,远程访问需要创建新用户并赋予权限。