依赖
<!--SpringAMQP起步依赖-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
yml配置文件
自行修改
spring:rabbitmq:host: 192.168.220.130 # 主机名port: 5672 # 端口virtual-host: / # 虚拟主机username: user # 用户名password: 123456 # 密码
SpringRabbitListener
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;@Component
public class SpringRabbitListener {@RabbitListener(queues = "demo.queue")public void listenDemoQueue(String message) {System.out.println("接收消息:" + message);}
}
测试
启动项目