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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。