Karsten B
Karsten B

Reputation: 1

How to delay of AMQ shutdown until after Camel Route shutdown in PaxExam Test

i am running

When i test my Camel routes having AMQ endpoints and the test method finishes, the AMQ is shutdown earlier than the Camel routes. Causing the routes endpoints throwing a lot of lost connection exceptions, especially when there are inflights. The start level of the AMQ is much lower than my routes. How can i ensure the shutdown sequence: - route, - amq, - servicemix ?

Upvotes: 0

Views: 182

Answers (1)

Matt Pavlovich
Matt Pavlovich

Reputation: 4316

Specify to have your Camel route (or test bundle) depend on the ActiveMQ broker service. When the bundles are being shutdown, they will be shutdown in reverse dependency order and the broker (which doesn't depend on any of your coded services) should shutdown towards the end.

<bean id="pooledConnectionFactory" 
class="org.apache.activemq.pool.PooledConnectionFactory"
init-method="start" destroy-method="stop">
 ...
</bean>

Updated:

  1. Add a reference to your blueprint file on the service providing the broker
  2. Add a 'depends-on' attribute to your Camel route
  3. This allows OSGi to deterministically configure the proper startup and shutdown based on explicit dependency vs arbitrary (what you have now) or a number-ordered convention.

    <camelContext depends-on="activemq-broker">
    </camelContext>
    
    <reference id="activemq-broker" 
        availability="mandatory" 
        timeout="5000"
        interface="org.osgi.service.cm.ManagedService" 
        filter="(service.pid=org.apache.servicemix.activemq.service)"/> 
    

Upvotes: 0

Related Questions