Springboot整合RabbitMQ实现发送接收消息

本文介绍了如何使用Springboot整合RabbitMQ实现消息发送和接收。通过创建producer和consumer两个Springboot项目,详细讲解了发送不同消息的步骤、配置交换机、队列和绑定关系,以及启动消费者监听的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、发送消息的步骤

在这里插入图片描述

二、项目准备

新建两个springboot项目,分别取名为producer 和 consumer。新建项目的时候引入Rabbitmq依赖。或者手动添加。

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

2.1 Producer

发送四种消息。

package com.rabbitmq.producer;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : pengweiwei
 * @date : 2020/1/30 6:31 下午
 */
@Component
public class MyProducer {
   
   

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void send(){
   
   
        amqpTemplate.convertAndSend("DIRECT_EXCHANGE","direct.key","I am a direct msg!!");
        amqpTemplate.convertAndSend("TOPIC_EXCHANGE","aaa.topic.key","I am a topic msg aaa !!");
        amqpTemplate.convertAndSend("TOPIC_EXCHANGE","bbb.topic.key","I am a topic msg bbb !!");
        amqpTemplate.convertAndSend("FANOUT_EXCHANGE","","I am a fanount msg!!"
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值