You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "kraythe ." <kr...@gmail.com> on 2013/09/18 17:12:58 UTC

Proper way to initialize Transaction management for Camel in an Application Server

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.

Re: Proper way to initialize Transaction management for Camel in an Application Server

Posted by Robert Simmons <kr...@gmail.com>.
The question would be what functionality do I loose in doing that? Will I have to set up components like ActiveMQ manually instead of just getting it out of jboss jndi?

Sent from my iPad

> On Sep 20, 2013, at 2:01 AM, Claus Ibsen <cl...@gmail.com> wrote:
> 
> Hi
> 
> You can use SimpleCamelServletContextListener which then does not use
> the JndiRegistry but the simple instead, which should be able to do
> the lookups.
> 
> See the docs at
> http://camel.apache.org/servletlistener-component.html
> 
>> On Thu, Sep 19, 2013 at 4:50 PM, kraythe <kr...@gmail.com> wrote:
>> So am I to understand that there is no way possible right now to do this in a
>> ServletListener component? Can I create a simple registry without blowing up
>> the construction of the context or do something else? I would really like to
>> enable this type of ACID transactions.
>> 
>> 
>> 
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Proper-way-to-initialize-Transaction-management-for-Camel-in-an-Application-Server-tp5739760p5739827.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen

Re: Proper way to initialize Transaction management for Camel in an Application Server

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can use SimpleCamelServletContextListener which then does not use
the JndiRegistry but the simple instead, which should be able to do
the lookups.

See the docs at
http://camel.apache.org/servletlistener-component.html

On Thu, Sep 19, 2013 at 4:50 PM, kraythe <kr...@gmail.com> wrote:
> So am I to understand that there is no way possible right now to do this in a
> ServletListener component? Can I create a simple registry without blowing up
> the construction of the context or do something else? I would really like to
> enable this type of ACID transactions.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Proper-way-to-initialize-Transaction-management-for-Camel-in-an-Application-Server-tp5739760p5739827.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Proper way to initialize Transaction management for Camel in an Application Server

Posted by kraythe <kr...@gmail.com>.
So am I to understand that there is no way possible right now to do this in a
ServletListener component? Can I create a simple registry without blowing up
the construction of the context or do something else? I would really like to
enable this type of ACID transactions. 



--
View this message in context: http://camel.465427.n5.nabble.com/Proper-way-to-initialize-Transaction-management-for-Camel-in-an-Application-Server-tp5739760p5739827.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Proper way to initialize Transaction management for Camel in an Application Server

Posted by Robert Simmons <kr...@gmail.com>.
Yes I am. Same person btw, just a different email.

Sent from my iPad

> On Sep 19, 2013, at 4:00 AM, Claus Ibsen <cl...@gmail.com> wrote:
> 
> Hi
> 
> I have logged ticket to implement the empty methods in JndiRegistry
> https://issues.apache.org/jira/browse/CAMEL-6769
> 
> Just to be sure are you using?
> http://camel.apache.org/servletlistener-component.html
> 
>> On Wed, Sep 18, 2013 at 5:12 PM, kraythe . <kr...@gmail.com> wrote:
>> 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.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen

Re: Proper way to initialize Transaction management for Camel in an Application Server

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I have logged ticket to implement the empty methods in JndiRegistry
https://issues.apache.org/jira/browse/CAMEL-6769

Just to be sure are you using?
http://camel.apache.org/servletlistener-component.html

On Wed, Sep 18, 2013 at 5:12 PM, kraythe . <kr...@gmail.com> wrote:
> 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.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen