ActiveMQ使用启动参数设置属性

时间:2016-03-09 10:05:44

标签: activemq

有没有办法将activemq.xml中定义的某些属性(例如共享存储)设置为启动参数?

<kahaDB directory="${data}/kahadb"/>

使用-Dparam = value运行amq似乎不起作用

1 个答案:

答案 0 :(得分:0)

我觉得这对你不起作用很奇怪,例如我们目前正在使用以下Broker配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="ignoreResourceNotFound" value="true" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="locations">
            <list>
                <value>classpath:activemq.properties</value>
                <value>file:///${user.home}/activemq.properties</value>
                <value>file:///#{systemProperties['activemq.properties']}</value>
            </list>
        </property>
    </bean>

    <broker useJmx="${activemq.expose.jmx}" persistent="false"
        brokerName="${activemq.brokerName}"
        xmlns="http://activemq.apache.org/schema/core">
        <destinationPolicy>
            <policyMap>
                <policyEntries>
                    <policyEntry queue=">" enableAudit="false">
                        <networkBridgeFilterFactory>
                            <conditionalNetworkBridgeFilterFactory replayWhenNoConsumers="true"/>
                        </networkBridgeFilterFactory>
                    </policyEntry>
                </policyEntries>
            </policyMap>
        </destinationPolicy>
        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="${activemq.memoryUsage}" />
                </memoryUsage>
                <tempUsage>
                    <tempUsage limit="${activemq.tempUsage}" />
                </tempUsage>
            </systemUsage>
        </systemUsage>
        <networkConnectors>
            <networkConnector
                name="queues"
                uri="static:(${activemq.otherBrokers})"
                networkTTL="3"
                decreaseNetworkConsumerPriority="true"
                conduitSubscriptions="false" >
                <excludedDestinations>
                    <topic physicalName=">" />
                </excludedDestinations>
            </networkConnector>
            <networkConnector
                name="topics"
                uri="static:(${activemq.otherBrokers})"
                networkTTL="3"
                decreaseNetworkConsumerPriority="true"
                conduitSubscriptions="true" >
                <excludedDestinations>
                    <queue physicalName=">" />
                </excludedDestinations>
            </networkConnector>
        </networkConnectors>
        <transportConnectors>
            <!-- expose a TCP transport for clients to use -->
            <transportConnector
                uri="${activemq.protocol}${activemq.host}:${activemq.tcp.port}"
                updateClusterClients="true"
                rebalanceClusterClients="true" />
            <transportConnector
                uri="${activemq.websocket.protocol}${activemq.websocket.host}:${activemq.websocket.port}"
                updateClusterClients="true"
                rebalanceClusterClients="true" />
        </transportConnectors>
    </broker>
</beans>

这里通常从给定的属性文件中读取属性,但是我经常使用直接-D JMV系统属性来取代属性文件中的属性以进行某些测试,并且从未遇到任何问题。我猜你可以尝试#{systemProperties [&#39; property.name&#39;]}的更复杂的语法来专门设置给定属性是系统属性而不是占位符。

最后一点:您使用的ActiveMQ版本以及此版本使用的是哪个版本的spring?我认为整个占位符语法是在春季3.1附近添加的,所以很久以前,但这是我能想象为什么它不适合你的唯一原因。

相关问题