5

我正在使用 ActiveMQ 蓝图来设置 JMS 连接池。我还使用 Camel 来提供一些功能。

我使用org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer允许在设置文件时使用外部属性camel-context文件。

是否有使用蓝图的类似类型功能?

所以基本上,我想用我从以下配置中的属性文件中获得的属性替换 ${server.address}:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
        xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
        xmlns:amq="http://activemq.apache.org/schema/core">

        <bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
             <property name="brokerURL"
                       value="nio://${server.address}" />
        </bean>

        <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
             <property name="maxConnections" value="8" />
             <property name="connectionFactory" ref="activemqConnectionFactory" />
        </bean>

        <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
             <property name="connectionFactory" ref="pooledConnectionFactory" />
             <property name="concurrentConsumers" value="5" />
        </bean>

        <bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager"
             init-method="recoverResource">
             <property name="transactionManager" ref="transactionManager" />
             <property name="connectionFactory" ref="activemqConnectionFactory" />
             <property name="resourceName" value="activemq.localhost" />
        </bean>

        <bean id="xaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
             <argument value="nio://${server.address}" />
        </bean>

        <bean id="connectionFactory" class="org.fusesource.jms.pool.JcaPooledConnectionFactory"
             init-method="start" destroy-method="stop">
             <property name="connectionFactory" ref="pooledConnectionFactory" />
             <property name="name" value="activemq" />
        </bean>

        <reference id="transactionManager" interface="javax.transaction.TransactionManager" />

        <service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory">
                <service-properties>
                        <entry key="name" value="localhost" />
                </service-properties>
        </service> 
</blueprint>
4

1 回答 1

8

您可以通过配置管理员使用系统属性和/或配置:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
    xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">

    <!-- Allow the use of system properties -->
    <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]" />

    <!--
        config admin properties from etc/com.example.config.cfg
    -->
    <cm:property-placeholder persistent-id="com.example.config" update-strategy="reload">
        <cm:default-properties>
            <cm:property name="configDir" value="$[karaf.base]/my-config" />
        </cm:default-properties>
    </cm:property-placeholder>

    <bean id="config" class="com.example.Config">
        <property name="rootDir" value="${configDir}" />
        <property name="someSysProp" value="$[someSysProp]" />
    </bean>

</blueprint>

“ext:property-placeholder”元素允许您通过定义的占位符前缀和后缀使用系统属性(如示例中的 karaf.base),但这是可选的。如果您只需要自己的配置,您可以通过 etc/etc/com.example.config.cfg 中的文件提供它,并通过 persistence-id 引用它。

于 2013-03-11T08:55:10.483 回答