Hi.

I'm trying out camel for the first time.

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...

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.

Other examples I find uses routes and policy... but I want @Transactional.
Is this possible? I'm really confused.

Thanks!

-- 

 /Magnus Heino

Reply via email to