美文网首页
9.1.跟我学SpringBoot-整合rabbitmq

9.1.跟我学SpringBoot-整合rabbitmq

作者: 孔垂云 | 来源:发表于2017-12-04 00:03 被阅读0次

在讲这一篇之前,你首先要知道什么是RabbitMq,做什么用,怎么安装,细节请查看
8.1RabbitMq安装及使用
8.2 RabbitMQ与Spring整合
8.3 RabbitMQ消息消费

1.maven配置

<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>

通过增加spring-boot-starter-amqp来引用RabbitTemplate实现队列的调用

2.application.yml

spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: test1
    password: 123
    virtualHost: /

配置各个参数

3.测试把消息放入队列TestRabbitmq.java

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestRabbitmq {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void testSend() {
        rabbitTemplate.convertAndSend("test_mq", "SpringBoot发送消息");
    }
}

可以看到调用rabbitTemplate.convertAndSend就可以发送消息了,非常简单。

源码下载

本例子详细源码

相关文章

网友评论

      本文标题:9.1.跟我学SpringBoot-整合rabbitmq

      本文链接:https://www.haomeiwen.com/subject/tqgobxtx.html