Thanks Martin,
I'm still not having any luck. There is a difference between my setup and
the one you have below, so I'm trying to meld your config and mine.
I've added the following to my camel config file:
<bean id="mqseries" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="transactionTemplate" />
<property name="transacted" value="true"/>
</bean>
<bean id="transactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="jmsTransactionManager"/>
</bean>
<bean id="jmsTransactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="myProxyConnectionFactory" />
</bean>
The way I'm invoking the program is as follows:
public class MQPrinter extends RouteBuilder {
public static void main(String[] args) {
new Main().run(args);
}
public void configure() {
...same code as before...
}
}
The reason I'm using the method above is because it gives me a very
convenient way of starting up the program and letting it build everything
and enter the main processing loop without me having to write that code.
Martin Krasser wrote:
>
> Hi Stephen,
>
> I had a similar problem and solved it this way (using ActiveMQ but this
> should also work with mqseries):
>
> First, I defined a transaction template in spring
>
> <bean id="PROPAGATION_REQUIRED"
> class="org.springframework.transaction.support.TransactionTemplate">
> <property name="transactionManager" ref="jmsTransactionManager"/>
> </bean>
>
> ... along with the dependencies
>
> <bean id="jmsTransactionManager"
> class="org.springframework.jms.connection.JmsTransactionManager">
> <property name="connectionFactory" ref="jmsConnectionFactory" />
> </bean>
>
> <bean id="jmsConnectionFactory"
> class="org.apache.activemq.ActiveMQConnectionFactory">
> (... amq specific properties ...)
> </bean>
>
> I am using a SpringRouteBuilder to refer to beans when configuring routes.
> In the configure() method I defined a transaction policy
>
> Policy required = new SpringTransactionPolicy(
> bean(TransactionTemplate.class, "PROPAGATION_REQUIRED"));
>
> ... and use it in the route definition:
>
> from("activemq:queue.a").policy(required).process(new Processor() {
> @Override
> public void process(Exchange exchange) throws Exception {
> throw new Exception("test");
> }
> });
>
> This installs a transaction interceptor that reacts on the "test"
> exception
> and initiates a rollback.
>
> To setup the camel context I used:
>
> ApplicationContext springContext = new
> ClassPathXmlApplicationContext("/context.xml");
>
> SpringCamelContext camelContext =
> SpringCamelContext.springCamelContext(springContext);
>
> JmsComponent jmsConponent = JmsComponent.jmsComponentTransacted(
> (ConnectionFactory)springContext.getBean("jmsConnectionFactory"),
> (PlatformTransactionManager)springContext.getBean("jmsTransactionManager"));
>
> camelContext.addComponent("activemq", jmsConponent);
>
>
> Hope this helps.
>
> Cheers,
> Martin
>
>> -----Ursprüngliche Nachricht-----
>> Von: Stephen J [mailto:[EMAIL PROTECTED]
>> Gesendet: Dienstag, 29. Januar 2008 22:22
>> An: [email protected]
>> Betreff: Re: JMS Transactions - How To
>>
>>
>> --camel config--
>> <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
>> <package>cameltest</package>
>> </camelContext>
>>
>> <bean id="mqseries"
>> class="org.apache.camel.component.jms.JmsComponent">
>> <property name="connectionFactory" ref="myProxyConnectionFactory" />
>> <property name="transacted" value="true"/>
>> </bean>
>>
>> <bean id="myProxyConnectionFactory"
>> class="org.springframework.jms.connection.UserCredentialsConnectionFactory
>> Adapter">
>> <property name="targetConnectionFactory" ref="mqConFactory"/>
>> <property name="username" value=" "/>
>> <property name="password" value=" "/>
>> </bean>
>>
>> <bean id="mqConFactory" class="com.ibm.mq.jms.MQConnectionFactory">
>> (properties to connect to my mqseries machine)
>> </bean>
>>
>> --RouteBuilder code--
>> public void configure() {
>> from("mqseries:integrator_test").process(new Processor() {
>>
>> public void process(Exchange exch) throws Exception
> {
>> Process print =
> Runtime.getRuntime().exec("execute
>> print command");
>> if(print.returnVal != 0) {
>> throw new Exception("Print was not
>> successful.");
>> }
>> }
>>
>> });
>> }
>>
>> Thanks for any help.
>>
>>
>> Hadrian Zbarcea wrote:
>> >
>> > Hi, not sure how you set up your routes. There is a
>> > TransactedJmsRouteTest you could look at or you could send your whole
>> > configuration.
>> >
>> > Cheers
>> > Hadrian
>> >
>> > On Jan 29, 2008, at 3:45 PM, Stephen J wrote:
>> >
>> >>
>> >> I am trying to create a small program that reads off an mqseries jms
>> >> queue
>> >> and prints some of the information in the message to a printer. I
>> >> would like
>> >> to encapsulate the code in a transaction, so that if a problem
>> >> occurs with
>> >> the printer, the message will stay on the queue until the problem is
>> >> resolved.
>> >>
>> >> I've tried adding the transacted property to my JmsComponent as
>> >> follows:
>> >>
>> >> <property name="transacted" value="true"/>
>> >>
>> >> But, when the program reads from the queue and fails to print, the
>> >> message
>> >> is gone from the queue. In other words, the rollback doesn't seem to
>> >> occur.
>> >>
>> >> Please let me know if I need to add additional code to make the
>> >> rollback
>> >> happen.
>> >>
>> >> Thanks,
>> >> Stephen
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/JMS-Transactions---How-To-
>> tp15168958s22882p15168958.html
>> >> Sent from the Camel - Users mailing list archive at Nabble.com.
>> >>
>> >
>> >
>> >
>>
>> --
>> View this message in context: http://www.nabble.com/JMS-Transactions---
>> How-To-tp15168958s22882p15169641.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
>
--
View this message in context:
http://www.nabble.com/JMS-Transactions---How-To-tp15168958s22882p15183634.html
Sent from the Camel - Users mailing list archive at Nabble.com.