camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quinn Stevenson <qu...@pronoia-solutions.com>
Subject Re: SJMS transaction
Date Wed, 10 Feb 2016 23:48:39 GMT
I don’t think you want DUPS_OK_ACKNOWLEDGE and transacted both set.

As long as both queues are in the same ActiveMQ broker, all you should need is the “transacted=true”
URI option for both the consumer and producer.

If you have multiple ActiveMQ brokers involved, you’ll need to use camel-jms - camel-sjms
doesn’t support XA.


> On Feb 10, 2016, at 3:18 AM, d1x <zdenek.obst@gmail.com> wrote:
> 
> Hello,
> 
> is there a way how to ensure transactions between consumer-producer of two
> JMS queues using SJMS component? 
> 
> What I'm testing is this simple case:
> 1. prepare higher amount of JMS messages in broker (e.g. 1000)
> 2. have Camel route from input queue to output queue
> 3. start context (starts consuming messages) and in any time kill java
> process
> 
> What I would expect is that sum of messages in input queue and output queue
> will be 1000. But what happens is that the sum is higher (something between
> 1000 and 1005 as I use 5 parallelConsumers). It is because when I kill
> process in the time when JMS message was already submitted to JMS output
> queue - it will remain there even if the transaction (acknowledge) of
> message from input queue did not succeed (because of kill). 
> 
> I tried hard to find out how to configure Apache Camel properly. From what I
> understood from documentation is that I cannot use Camel Transaction
> Processor. But still there are options like acknowledgementMode (but their
> options seem not documented at all, not even in source code).
> 
> So is there a way how to configure SJMS component to behave fully
> transactionally between consumer-producer? Very likely they will use the
> same JMS session or use other way of synchronization?
> 
> Here is the simple code I use for testing
> 
> public class SjmsTransaction {
> 
>    public static void main(String[] args) throws Exception {
>        RouteBuilder rb = new RouteBuilder() {
>            @Override
>            public void configure() throws Exception {
> 
> from("sjms:queue:test-in?transacted=true&acknowledgementMode=DUPS_OK_ACKNOWLEDGE&consumerCount=5")
> //                        .setExchangePattern(ExchangePattern.InOut)
>                        .process(new Processor() {
>                            @Override
>                            public void process(Exchange exchange) throws
> Exception {
>                                System.out.println("Processed message " +
> exchange.getExchangeId());
>                            }
>                        })
>                        .to("sjms:queue:test-out?transacted=true");
>            }
>        };
> 
>        CamelContext context = new DefaultCamelContext();
>        addJmsComponent(context);
>        context.addRoutes(rb);
> 
>        System.out.println("=====> Starting context");
>        context.start();
>        // Now the context will run and consume messages, when I stop
> application by force in any time
>        // I expect this to be true: <#submittedMessages> ==
> <#messagesInInput> + <#messagesInOutput>
>        // What happens is that there more messages that was not
> acknowledged (from input) but are already in output
>    }
> 
>    private static void addJmsComponent(CamelContext context) {
>        ConnectionFactory factory = new
> ActiveMQConnectionFactory("tcp://localhost:61616");
>        ConnectionFactoryResource connResource = new
> ConnectionFactoryResource(5, factory);
>        SjmsComponent comp = new SjmsComponent();
>        comp.setConnectionResource(connResource);
>        context.addComponent("sjms", comp);
>    }
> }
> 
> Thank you very much for any answer
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/SJMS-transaction-tp5777522.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message