您好,登錄后才能下訂單哦!
spring整合rabbitmq的步驟:
在maven的pom文件中添加如下:
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.6.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.1.3</version>
</dependency>
在bean工廠中添加連接工廠和rabbitAdmin實例
@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:創建隊列
to :綁定交換機
with :路由key
底層是通過rabbitTemplate調用execute方法
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。