如何从外部启动spring RabbitMQ Listerner

问题描述 投票:0回答:1

我有一个要求,我的兔子mq使用者不应在bootRun上使用该消息。但是,消费者必须在完成其他一些依赖项目的部署之后才开始使用消息。

我已设置autostart =“ false”以确保在bootRun上不使用队列中的消息。此配置运行良好,并且在bootRun之后不使用队列中的消息。

@RabbitListener(id = LISTENER_ID,
            bindings = @QueueBinding(exchange = @Exchange(value = "${listener.exchange}", type = "topic"),
                    value = @Queue(value = "${listener.queue}", durable = "true"), key = "${listener.routingKey}"),
            containerFactory = "rabbitListenerContainerFactory" , autoStartup = "false")
    public void receiveMessage(@Valid @Payload RequestMessage requestMessage,
            @Headers Map<String, Object> requestHeaders) {
//some code here
}

我想从其他外部(我的项目外部)启动此侦听器,以在其他依赖项项目部署结束后开始使用队列中的消息。我有什么办法可以做到这一点?

spring-boot rabbitmq spring-amqp
1个回答
0
投票

使用RabbitListenerEndpointRegistry @Bean启动/停止容器。

registry.getListenerContainer(LISTENER_ID).start();
© www.soinside.com 2019 - 2024. All rights reserved.