Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aries Blueprint in Karaf - Can a blueprint reference an external properties file

I am using an ActiveMQ blueprint to setup a JMS Connection Pool. I also use Camel to service some functionality.

I use the org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer to allow the use of an external properties file in setting up the camel-context file.

Is there a similar type functionality using blueprints?

So basically, I want to replace ${server.address} with a property I get from a property file in the configuration below:

<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>
like image 380
user2130332 Avatar asked Mar 11 '13 02:03

user2130332


People also ask

What is blueprint in Karaf?

karaf-blueprint-example-provider implements and exposes a BookingService using a Blueprint XML file. karaf-blueprint-example-client uses OSGI-INF/blueprint/client. xml Blueprint XML to get a service and start a thread. karaf-blueprint-example-features contains a Karaf features repository used for the deployment.

What is blueprint OSGi?

Blueprint provides a dependency injection framework for OSGi and was standardized by the OSGi Alliance in OSGi Compendium R4. 2. It is designed to deal with the dynamic nature of OSGi, where services can become available and unavailable at any time.

What is blueprint XML?

A Blueprint XML file is identified by a top-level blueprint element and contains definitions of component managers such as a bean manager, a service manager, and service reference managers. A Blueprint XML file is identified by a top-level Blueprint element, as shown in the following blueprint.

What is Karaf container?

Apache Karaf is a modern polymorphic application container. Karaf can be used as a standalone container, supporting a wide range of applications and technologies. It also supports the "run anywhere" concept (on any machine with Java, cloud, docker images, … ​) using the embedded mode.


1 Answers

You can use System properties and/or configuration via the config admin:

<?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>

The "ext:property-placeholder" element allows you to use system properties (like karaf.base in the example) via the defined placeholder pre- and suffix, but this is optional. If you only need your own configuration you can provide it via a file in etc/ etc/com.example.config.cfg and reference it via the persistence-id.

like image 197
apf7188 Avatar answered Oct 04 '22 09:10

apf7188