spring整合rabbitmq的步驟:
在maven的pom文件中添加如下:
com.rabbitmq
amqp-client
3.6.5
org.springframework.boot
spring-boot-starter-amqp
2.1.3
在bean工廠中添加連接工廠和rabbitAdmin實(shí)例
@Bean
public ConnectionFactory connectionFactory(){
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setAddresses("192.168.1.177:5672");
connectionFactory.setUserName("guest");
connectionFactory.setUserName("guest");
connectionFactory.setVirtualHost("/");
return connectionFactory;
}
@Bean
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory){
RabbitAdmin rabbitAdmin = new RabbitAdmini(connectionFactory);
rabbitAdmin.setAutoStartup(true);
return rabbitAdmin;
}
利用rabbitAdmin聲明:
rabbitAdmin.declareBinding(BindingBuilder.bind(new Queue("topic.queue"),false).to(new TopicExchange("topic".false,false)).with("test.#"));
bind:創(chuàng)建隊(duì)列
to :綁定交換機(jī)
with :路由key
底層是通過rabbitTemplate調(diào)用execute方法
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動(dòng)態(tài)BGP最優(yōu)骨干路由自動(dòng)選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機(jī)房獨(dú)有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進(jìn)行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動(dòng)現(xiàn)已開啟,新人活動(dòng)云服務(wù)器買多久送多久。