Set the bundle version and start level when deploying camel route as XML in deploy folder of ServiceMix

337 views Asked by At

When deploying bundle in the "deploy" folder in ServiceMix, I am wondering if it is possible to set the bundle version in the blueprint XML.

Example of Camel route (blueprint xml):

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
       http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">


    <cm:property-placeholder persistent-id="my.deploy.route" update-strategy="reload">
        <cm:default-properties>
            <cm:property name="amq.url" value="tcp://my-amq-host:61616?jms.watchTopicAdvisories=false" />
            <cm:property name="tracer.enable" value="false" />
        </cm:default-properties>
    </cm:property-placeholder>

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <onException useOriginalMessage="true">
            <exception>java.lang.Exception</exception>
            <handled>
                <constant>true</constant>
            </handled>
            <to uri="activemq:queue:SYNCHRO.DLQ" />
        </onException>

        <route id="route-countries">
            <from uri="activemq:queue:SYS.SOURCE.COUNTRY" />
            <to uri="activemq:queue:OTHER.DESTINATION.COUNTRY" />
        </route>

    </camelContext>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="${amq.url}" />
    </bean>
</blueprint>

And when deployed, the list in the smx console shows:

[1233] [Active     ] [Created     ] [       ] [   80] country-route-dev.xml (0.0.0)

I would like to know if it's also possible to change the start level which is defaulted to 80.

2

There are 2 answers

1
user75654 On BEST ANSWER

I know you said ServiceMix and this only sets the version not the start-level but this works for me in karaf:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<manifest xmlns="http://karaf.apache.org/xmlns/deployer/blueprint/v1.0.0">
Bundle-SymbolicName My Cool Bundle
Bundle-Version: 1.2.3
</manifest>

https://svn.apache.org/repos/asf/karaf/site/production/manual/latest/deployers.html#_blueprint_deployer

1
Alexey Yakunin On

It probably won't be the most convenient solution, but :

You can create a Maven project with such structure

src
- main
- - resources
- - - OSGI-INF 
- - - - blueprint
- - - - -  blueprint.xml
pom.xml

Necessarily:

<packaging>bundle</packaging>

In the pom.xml you can set all the bundle parameters you need:

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.7</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Description>${project.description}</Bundle-Description>
                    <Bundle-Version>1.0.0</Bundle-Version>
                    <Import-Package>*</Import-Package>
                </instructions>
            </configuration>
        </plugin>

Build your bundle and get the jar file for deployment

The level of the bundle is started, you can define in the config.properties

#
# Definition of the default bundle start level
#
org.osgi.framework.startlevel.beginning=100
karaf.startlevel.bundle=80

Also you can create feature for your bundle and reset start level:

  <feature name="my-project" version="1.0.0">
    <bundle start-level="80" start="false">mvn:com.mycompany.myproject/myproject-dao</bundle>
    <bundle start-level="85" start="false">mvn:com.mycompany.myproject/myproject-service</bundle>
  </feature>