On 07/02/2008, Magnus Heino <[EMAIL PROTECTED]> wrote:
> Hi.
>
> I'm trying out camel for the first time.
Welcome! :)
> I have Spring, Camel, JBoss and Tibco EMS.
>
> My spring service:
>
> @Component
> public class UpdateService {
>
> @EndpointInject(uri = "jms:queue:foobar")
> private ProducerTemplate producer;
>
> private final Logger logger = LoggerFactory.getLogger(this.getClass());
>
> /**
> * Handle message from Apache Camel
> *
> * @param message
> */
> @Transactional
> @MessageDriven(uri = "jms:queue:foobar")
> public void handleMessage(final String message) {
> this.logger.info("Message received: '{}'", message);
> }
>
> /**
> * Simple jms test
> */
> public void send() {
> this.logger.debug("Sending Jms message");
> this.producer.sendBody("demo");
> }
> }
>
> And configuration:
>
> <context:component-scan base-package="se.lantmateriet.origo" />
>
> <tx:annotation-driven />
>
> <jee:jndi-lookup id="jmsConnectionFactory"
> jndi-name="java:JmsConnectionFactory" />
>
> <bean id="transactionManager" class="
> org.springframework.transaction.jta.JtaTransactionManager" />
>
> <bean class="org.apache.camel.component.jms.JmsComponent">
> <property name="connectionFactory" ref="jmsConnectionFactory" />
> <property name="transactionManager" ref="transactionManager" />
> <property name="transacted" value="true" />
> </bean>
>
> <camel:camelContext />
>
> <bean id="scheduledTask" class="
> org.springframework.scheduling.timer.ScheduledTimerTask">
> <!-- wait 5 seconds before starting repeated execution -->
> <property name="delay" value="5000" />
> <!-- run every 5 seconds -->
> <property name="period" value="5000" />
> <property name="timerTask">
> <bean id="doIt" class="
> org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
> <property name="targetObject" ref="updateService" />
> <property name="targetMethod" value="send" />
> </bean>
> </property>
> </bean>
>
> <bean id="timerFactory" class="
> org.springframework.scheduling.timer.TimerFactoryBean">
> <property name="scheduledTimerTasks">
> <list>
> <!-- see the example above -->
> <ref bean="scheduledTask" />
> </list>
> </property>
> </bean>
>
> The timer stuff is to trigger a send of a new message every 5s.
>
> I want the @MessageDriven method to consume the messages in a XA
> transaction. Right now messages are sent and received, but no transactions
> exists... if I restart my app, I get all messages one again.. and again...
So the transaction manager is passed down to the underlying
MessageListenerContainer in spring by the JMS component. So it should
be using your transaction manager to process your @MessageDriven
method.
> Also a related queston. If I don'e use @MessageDriven, and configure a route
> using bean:updateService, it doesn't work since <tx:annotation-driven /> has
> created a cglib-extended class with a final method with the same arguments
> as my handleMessage method.
You could always use the explicit method name?
from(...).beanRef("updateService", "myMethod");
> Other examples I find uses routes and policy... but I want @Transactional.
> Is this possible? I'm really confused.
It should be. The Camel endpoint will typically set the transaction up
before invoking your bean; so you don't need to create a dynamic proxy
of your bean with a transaction interceptor around it.
I wonder if your problem is with the JTA transaction manager; which
depends on an XA aware ConnectionFactory? Maybe using the JMS
transaction manager might work better; then TibCo doesn't need to do
XA stuff?
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://open.iona.com