时间:2024-9-1 作者:老大夫 分类: RabbitMQ
@Test
public void testSendMessage() {
for (int i = 0; i < 100; i++) {
rabbitTemplate.convertAndSend(
EXCHANGE_DIRECT,
ROUTING_KEY,
"Hello atguigu" + i);
}
}
// 2、正常业务操作
log.info("消费端接收到消息内容:" + dataString);
// System.out.println(10 / 0);
TimeUnit.SECONDS.sleep(1);
// 3、给 RabbitMQ 服务器返回 ACK 确认信息
channel.basicAck(deliveryTag, false);
说明:
接下来启动消费端程序,再查看队列情况:
spring:
rabbitmq:
host: 192.168.200.100
port: 5672
username: guest
password: 123456
virtual-host: /
listener:
simple:
acknowledge-mode: manual
prefetch: 1 # 设置每次最多从消息队列服务器取回多少消息
推荐阅读:
RabbitMQ交换机类型
Operation007-SpringBoot
Operation019-Federation
Operation006-Topics
Operation018-Stream
Operation004-PubSub
Operation001-Install
Operation008-Confirm01-A-Producer生产者端消息确认机制
Operation020-Shovel
Operation005-Routing
行动消除疑虑