欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 【RabbitMQ】02-Spring AMQP

【RabbitMQ】02-Spring AMQP

2025/2/24 0:34:16 来源:https://blog.csdn.net/qq_45722630/article/details/143465245  浏览:    关键词:【RabbitMQ】02-Spring AMQP

1. 使用

  1. 依赖
<!--AMQP依赖,包含RabbitMQ--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency>
  1. 配置
spring:rabbitmq:host: 192.168.150.101 # 你的虚拟机IPport: 5672 # 端口virtual-host: /hmall # 虚拟主机username: hmall # 用户名password: 123 # 密码
  1. 生产者
@SpringBootTest
public class SpringAmqpTest {@Autowiredpublic RabbitTemplate rabbitTemplate;@Testvoid testSimple() {rabbitTemplate.convertAndSend("simple.queue", "hello, w");}
}
  1. 消费者
    注册为Bean,交给SpringBoot进行管理。
@Component
@Slf4j
public class SpringAmqbListener {@AutowiredRabbitTemplate rabbitTemplate;@RabbitListener(queues = "simple.queue")public void Lister(String msg) {log.info(msg);}
}
  1. 能者多劳
    处理完了,才能获取下一条消息。
spring:rabbitmq:host: nuaamvp.cn # 你的虚拟机IPport: 5672 # 端口virtual-host: /hmall # 虚拟主机username: hmall # 用户名password: "@Mvplab123" # 密码listener:simple:prefetch: 1

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词