我正在尝试从springboot应用程序向RabbitMQ发送消息。使用的依赖项(springboot和amqp):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
我可以使用具有以下访问权限(读取,写入和配置)的用户凭据将消息发布到交换机:
但是当我使用如下没有配置权限的用户时,它将失败:
调用rabbitTemplate.convertAndSend(exchange, null, message);
时收到错误:
CachingConnectionFactory : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to exchange 'MyExchangeName' in vhost 'my_vHost' refused for user 'my_user', class-id=40, method-id=10
我认为是因为Spring尝试创建交换或检查交换是否存在(使用Admin API)。如果是这种情况,我们可以使用某些属性将其禁用吗?
要么删除任何Exchange/Queue/Binding
@Bean
,要么将shouldDeclare
属性设置为false
。