需要导入依赖
<!--rabbitmq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
properties文件的配置信息
#配置RabbitMQ的消息(单机版)
spring.rabbitmq.host=192.168.79.141
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=123456
该用户名和密码是登录RabbitMQ的用户名和密码
发送消息函数
amqpTemplate.convertAndSend(String exchange, String routingKey, Object message)
参数 | 含义 |
---|---|
exchange | 交换机名称 |
routingKey | routingKey |
message | 具体发送的消息 |
案例
发送方
项目目录
TestServiceImpl:
@Service("sendService")
public class TestServiceImpl implements TestService {
<