问题 从spring application.properties禁用侦听rabbit队列


我想在spring中创建一个application-development.properties文件来定义开发环境。在这种环境中想要禁用侦听兔子队列,因为我不想在调试等时干扰登台队列。

问题是 - 我找不到控制它的属性。没有“有效”属性或“已启用”属性或任何内容..

这些是我在中找到的属性 春天的文档

# RABBIT (RabbitProperties)
spring.rabbitmq.addresses= # connection addresses (e.g. myhost:9999,otherhost:1111)
spring.rabbitmq.dynamic=true # create an AmqpAdmin bean
spring.rabbitmq.host= # connection host
spring.rabbitmq.port= # connection port
spring.rabbitmq.password= # login password
spring.rabbitmq.requested-heartbeat= # requested heartbeat timeout, in seconds; zero for none
spring.rabbitmq.listener.acknowledge-mode= # acknowledge mode of container
spring.rabbitmq.listener.concurrency= # minimum number of consumers
spring.rabbitmq.listener.max-concurrency= # maximum number of consumers
spring.rabbitmq.listener.prefetch= # number of messages to be handled in a single request
spring.rabbitmq.listener.transaction-size= # number of messages to be processed in a transaction
spring.rabbitmq.ssl.enabled=false # enable SSL support
spring.rabbitmq.ssl.key-store= # path to the key store that holds the SSL certificate
spring.rabbitmq.ssl.key-store-password= # password used to access the key store
spring.rabbitmq.ssl.trust-store= # trust store that holds SSL certificates
spring.rabbitmq.ssl.trust-store-password= # password used to access the trust store
spring.rabbitmq.username= # login user
spring.rabbitmq.virtual-host= # virtual host to use when connecting to the broker

我确实找到了一种方法,可以通过使用加载包含侦听器定义的amqp-context.xml bean 弹簧型材 并添加 <beans profile="development"> .. </beans> 到xml,但由于我必须定义不同的配置文件,并且更改它们包含的内容涉及更改代码,因此灵活性要低得多。

编辑 这就是我的amqp-context.xml的样子:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:task="http://www.springframework.org/schema/task" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:rabbit="http://www.springframework.org/schema/rabbit"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/task
        http://www.springframework.org/schema/task/spring-task-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/rabbit 
        http://www.springframework.org/schema/rabbit/spring-rabbit-1.3.xsd">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
            <list>
                <value>application.${env:xxxx}.properties</value>
            </list>
        </property>
    </bean>
    <rabbit:connection-factory id="connectionFactory" host="${rabbit_host}"
        virtual-host="${rabbit_virtual_host}" username="${rabbit_username}" password="${rabbit_password}" port="${rabbit_port}"/>   

    <!-- Connection Factory -->
    <bean id="rabbitConnFactory"
        class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
    </bean>


    <!-- Spring AMQP Template -->
    <bean id="template" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="routingKey" value="${my_queue}" />
        <property name="queue" value="${my_queue}" />
    </bean>

    <!-- Spring AMQP Admin -->
    <bean id="admin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
        <constructor-arg ref="rabbitConnFactory" />
    </bean>

    <rabbit:listener-container connection-factory="connectionFactory" requeue-rejected="false" concurrency="10">
        <rabbit:listener ref="ProcessMessage"
            queue-names="${queue_name}" />
    </rabbit:listener-container> 

    <bean id="ProcessStuff" class="Process" />



</beans>

有没有人知道如何直接从application.properties文件管理队列侦听?请?


3673
2017-07-23 13:51


起源

你的amqp-context.xml是什么样的? - jst
@jst我把它添加到问题的内容中 - Adi


答案:


作为等待Boot 1.3的替代方法,您可以将自己的密钥添加到application-development.properties中

rabbit.auto-startup=false

然后像这样修改你的amqp-context.xml

<rabbit:listener-container connection-factory="connectionFactory" requeue-rejected="false" concurrency="10" auto-startup=${rabbit.auto-startup}>

7
2017-07-27 14:22



你能帮我解决相关问题吗? stackoverflow.com/questions/52068307/... - VedX


接得好!我创造了 #3587 这将针对Spring Boot 1.3进行处理

谢谢!


2
2017-07-23 14:28