RabbitMQ访问在Spring中被拒绝

axzmvihb  于 2022-11-08  发布在  RabbitMQ
关注(0)|答案(1)|浏览(521)

我试图将一个新队列绑定到一个现有的交换,但我正在处理这个错误,我不知道是什么问题。我不得不说,在尝试创建一个新队列之前,我过去可以使用相同的代码来完成,但现在它不起作用。

Shutdown Signal: channel error; protocol method: #method<channel.close>(reply-code=403, reply-text=ACCESS_REFUSED - access to exchange 'ex-people-updates' in vhost 'PEOPLE' refused for user 'people-consumer', class-id=40, method-id=10)

显示此消息5次后,将出现此消息:

Broker not available; cannot force queue declarations during start: java.io.IOException

然后应用程序运行。
RabbitMQ配置类如下所示:

@EnableRabbit
@Configuration
public class MQConfig {

    @Value("${people.queue}")
    public String queue;

    @Value("${people.exchange}")
    public String exchange;

    @Value("${people.routingkey}")
    public List<String> routingKeys;

    @Value("${spring.rabbitmq.username}")
    private String username;

    @Value("${spring.rabbitmq.password}")
    private String password;

    @Value("${spring.rabbitmq.addresses}")
    private String address;

    @Value("${spring.rabbitmq.vhost}")
    private String vHost;

    @Bean
    public Queue queue() {
        return new Queue(queue, true, false, false);
    }

    @Bean
    Exchange myExchange() {
        return ExchangeBuilder.topicExchange(exchange).durable(true).build();
    }

    @Bean
    Declarables bindings(TopicExchange exchange, Queue queue) {
        return new Declarables(routingKeys.stream()
                .map(key -> BindingBuilder
                        .bind(queue)
                        .to(exchange)
                        .with(key))
                .collect(Collectors.toList()));
    }

    @Bean
    public MessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    public ConnectionFactory connectionFactory() throws IOException {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
        connectionFactory.setAddresses(address);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        connectionFactory.setVirtualHost(vHost);
        connectionFactory.setPublisherReturns(true);

        return connectionFactory;
    }

    @Bean
    public AmqpAdmin amqpAdmin() throws IOException {
        return new RabbitAdmin(connectionFactory());
    }
}
eyh26e7m

eyh26e7m1#

reply-text=ACCESS_REFUSED -拒绝用户“people-consumer”访问虚拟主机“PEOPLE”中的exchange“ex-people-updates”
这显然意味着您的用户没有将队列绑定到该交换的(配置)权限。

相关问题