与Spring集成

参考文档:

rabbitmq官网教程:http://www.rabbitmq.com/getstarted.html springboot官网教程:https://docs.spring.io/spring-amqp/docs/2.0.4.RELEASE/reference/html/

WEB登录界面

http://192.168.111.103:15672/

POM依赖

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-amqp</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

RabbitConfig配置

接受者

@RabbitListener 提供队列声明 官网介绍:https://docs.spring.io/spring-amqp/docs/2.0.4.RELEASE/reference/html/_reference.html#async-annotation-driven @RabbitHandler 不同类型的消息使用不同的方法来处理。

发送者

测试类

Last updated

Was this helpful?