camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "kraythe ." <kray...@gmail.com>
Subject Proper way to initialize Transaction management for Camel in an Application Server
Date Wed, 18 Sep 2013 15:12:58 GMT
Greetings, we are running Camel routes in JBoss AS7 and the problem I ran
into is that there is no transaction manager initialized to work with the
transacted routes. In my test code I did something like the following:

  @Override

  protected CamelContext createCamelContext() throws Exception {

    final SimpleRegistry registry = new SimpleRegistry();

    final CamelContext context = new DefaultCamelContext(registry);


    final BrokerService broker = getAMQBroker();

    final ActiveMQConnectionFactory amqcf =
newActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getUri());


    final PlatformTransactionManager txMgr = newJmsTransactionManager(amqcf);

    registry.put("transactionManager", txMgr);


    final SpringTransactionPolicy txPolicy = new SpringTransactionPolicy();

    txPolicy.setTransactionManager(txMgr);

    txPolicy.setPropagationBehaviorName("PROPAGATION_REQUIRED");

    registry.put("required", txPolicy);


    final ActiveMQComponent amq = (ActiveMQComponent) context.getComponent(
"activemq");

    amq.setConnectionFactory(amqcf);

    return context;

  }


I tried the same thing in the Lifecycle class:

  @Override

  public void beforeStart(final ServletCamelContext context,
finalJndiRegistry registry)
throws Exception {

    final ActiveMQConnectionFactory amqcf = (ActiveMQConnectionFactory)
registry.lookup("java:/activemq/ConnectionFactory");

    final PlatformTransactionManager txMgr = newJmsTransactionManager(amqcf);

    registry.bind("camel-transactionManager", txMgr);


    final SpringTransactionPolicy txPolicy = new SpringTransactionPolicy();

    txPolicy.setTransactionManager(txMgr);

    txPolicy.setPropagationBehaviorName("PROPAGATION_REQUIRED");

    registry.bind("required", txPolicy);

  }

The similar code in the CamelContextLifecycle didn't work because Camel
does a findByTypeWithName on the registry when looking for a transaction
manager and if you dig into 2.11.1 code findByType for the JNDIRegistry
eventually leads you to a method that returns an empty map.

    public <T> Map<String, T> findByTypeWithName(Class<T> type) {

        // not implemented so we return an empty map

        return Collections.emptyMap();

    }

As you can see this find will never work so as a result I get the error
that there is no platform transaction manager whenever I use a transacted
route.

Furthermore spring is off the table due to people here who hate spring and
cannot be shifted on that and have the power to make those decisions. So
how do I initialize a transaction manager for transacted routes in this
circumstance?

All help is appreciated.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message