Mula-mula bina projek SpringBoot dan tambahkan kebergantungan berikut dalam fail XML POM
<依赖> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-amqp</artifactid></依赖><依赖> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid></依赖>
Ubah suai fail konfigurasi dan tambah konfigurasi RabbitMQ berikut
rreeeKelas Constant awam baharu
服务器: port: 8888 # 设置端口号Spring: rabbitMQ: host: 127.0.0.1 # 设置 RabbitMQ 的主机 port: 5672 # 设置 RabbitMQ 服务端口 username: guest # 设置 RabbitMQ 用户名 password: guest # 设置 RabbitMQ 密码
Tambah kelas permintaan Pengawal (digunakan untuk mengesahkan keputusan, yang boleh ditambah pada penghujung)
public interface RabbitConstant { /** * 简单模式 */ String SIMPLE_QUEUE_NAME = "simple_queue"; /** * 工作模式 */ String WORK_QUEUE_NAME = "work_queue"; /** * 发布/订阅模式 */ String PUBLISH_SUBSCRIBE_EXCHANGE_NAME = "publish_subscribe_exchange"; 字符串 PUBLISH_SUBSCRIBE_FIRST_QUEUE_NAME = "publish_subscribe_first_queue"; 字符串 PUBLISH_SUBSCRIBE_SECOND_QUEUE_NAME = "publish_subscribe_second_queue"; /** * 路由模式 */ String ROUTING_EXCHANGE_NAME = "routing_exchange"; 字符串 ROUTING_FIRST_QUEUE_NAME = "routing_first_queue"; 字符串 ROUTING_SECOND_QUEUE_NAME = "routing_second_queue"; 字符串 ROUTING_THIRD_QUEUE_NAME = "routing_third_queue"; 字符串 ROUTING_FIRST_QUEUE_ROUTING_KEY_NAME = "routing_first_queue_routing_key"; 字符串 ROUTING_SECOND_QUEUE_ROUTING_KEY_NAME = "routing_second_queue_routing_key"; 字符串 ROUTING_THIRD_QUEUE_ROUTING_KEY_NAME = "routing_third_queue_routing_key"; /** * 主题模式 */ String TOPICS_EXCHANGE_NAME = "topics_exchange"; 字符串 TOPICS_FIRST_QUEUE_NAME = "topics_first_queue"; 字符串 TOPICS_SECOND_QUEUE_NAME = " 字符串 TOPICS_THIRD_QUEUE_NAME = "topics_third_queue"; String TOPICS_FIRST_QUEUE_ROUTING_KEY = "topics.first.routing.key"; String TOPICS_SECOND_QUEUE_ROUTING_KEY = "topics.second.routing.key"; String TOPICS_THIRD_QUEUE_ROUTING_KEY = "topics.third.routing.key"; 字符串 TOPICS_ROUTING_KEY_FIRST_WILDCARD = "#.first.#"; 字符串 TOPICS_ROUTING_KEY_SECOND_WILDCARD = "*.second.#"; 字符串 TOPICS_ROUTING_KEY_THRID_WILDCARD = "*.third.*"; /** * 标题模式 */ String HEADER_EXCHANGE_NAME = "header_exchange"; 字符串 HEADER_FIRST_QUEUE_NAME = "header_first_queue"; 字符串 HEADER_SECOND_QUEUE_NAME = "header_second_queue"; /** * rpc 模式 */ String RPC_QUEUE_NAME = "rpc_queue"; }
Atas ialah kandungan terperinci Bagaimana SpringBoot menyepadukan RabbitMQ. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!