前言
代码什么的在我的仓库里都有https://gitee.com/song_mengyu/Example/tree/master/Project/rabbit-ack-test
一、 配置
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
一、发送确认
首先是 yml的配置
server:
port: 8081
spring:
application:
name: rabbit-server
rabbitmq:
port: 5673
host: 192.168.136.128
username: admin
password: admin
publisher-confirms: true
publisher-returns: true
对于这个发送确认只是做个简单的演示,所以我我们就只设置个队列即可
@Configuration
public class Config {
@Bean
public Queue MyQueue(){
return new Queue("myQueue", true);
}
}
然后是发送的逻辑
package com.mymy;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Sender