springboot与mq(2)

本文介绍如何在Spring Boot项目中整合RabbitMQ,包括依赖配置、发送和接收消息的实现。通过示例代码展示了如何使用RabbitTemplate进行消息的发送与接收,以及如何配置RabbitMQ的相关参数。
 <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit</artifactId>
            <version>2.1.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-messaging</artifactId>
            <version>5.1.7.RELEASE</version>
        </dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.7.1</version>
</dependency>

  

@Autowired
RabbitTemplate rabbitTemplate;
private final static String Exchange_NAME ="hello";
String routingKey ="goods.delete";
private final static String QUEUE_NAME ="hello1";
@Test
public void send() throws Exception{
   Map<String,Object> map = new HashMap<>();
   map.put("1","haha");
    rabbitTemplate.convertAndSend("hello","goods.delete",map);
}
@Test
public void receive(){
    rabbitTemplate.receiveAndConvert(QUEUE_NAME);
}
spring:
  rabbitmq:
    host: 127.0.0.1
    username: mm
    password: 123
    port: 5672
    virtual-host: /test

 

转载于:https://www.cnblogs.com/mm163/p/10981109.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值