import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/rabbitmq")
public class RabbitMqController {
private static final String SUCCESS = "SUCCESS";
private static final String FAILURE = "FAILURE";
@Autowired
private Producer producer;
@GetMapping("/push")
public String push() {
producer.send();
return SUCCESS;
}
}
配置文件application.yml:
server:
port: 8081
spring:
rabbitmq:
host: 192.168.31.244
port: 5672
username: root
password: root
virtual-host: /
publisher-confirms: true
启动Spring Boot,访问::8081/rabbitmq/push,再切换到管理页面:
新的QUEUE NAME证明Spring Boot与RabbitMQ整合成功。
CentOS7环境安装使用专业的消息队列产品RabbitMQ