Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

understanding in/out exchange pattern behaviour in camel

In camel, is it correct to say that not all ENDPOINTs support INOUT ExchangePattern ?
If yes, then where which part of documentation tells which endpoint support which ExchangePattern or this is a implicit kind knowledge.

Its upto ENDPOINT to give support to INOUT.

Below is code example based on which i came to conclusion.


I was playing with camel example-jms-file and i modify it to

queue1 --> queue2 ---> file://test ---> file://test1

context.addRoutes(new RouteBuilder() {
        public void configure() {                         

            from("test-jms:queue:test.queue1")
            .process(sleep(1))
            .to("test-jms:queue:test.queue2");

            from("test-jms:queue:test.queue2")
            .process(sleep(2))
            .to("file://test");

            from("file://test")
            .process(sleep(3))
            .to("file://test1");
        }

        private Processor sleep(final int sleepId) {
            return new Processor() {                    
                @Override
                public void process(Exchange exchange) throws Exception {                       
                    System.out.println("Going for sleep sleepid=" + sleepId + ",  thread=" + Thread.currentThread().getName());
                    Thread.sleep(5000l);                        
                    System.out.println("Done sleep sleepid=" + sleepId + ",  thread=" + Thread.currentThread().getName());
                }
            };
        }
    });

Then i send a msg to queue using below code:

        Exchange exchange = new DefaultExchange(context);
        exchange.setPattern(ExchangePattern.InOut);
        exchange.getIn().setBody("Test Message: 1");
  System.out.println("sending msg to queue1");
       Exchange send = template.send("test-jms:queue:test.queue1",exchange);
  // If queue and file endpoint support INOUT then below line should get printed at last.
  System.out.println("received response"); 

Executing above give following response:

sending msg to queue1  

Going for sleep sleepid=1,  thread=Camel (camel-1) thread #0 - JmsConsumer[test.queue1]

Done sleep sleepid=1,  thread=Camel (camel-1) thread #0 - JmsConsumer[test.queue1]

Going for sleep sleepid=2,  thread=Camel (camel-1) thread #1 - JmsConsumer[test.queue2]

Done sleep sleepid=2,  thread=Camel (camel-1) thread #1 - JmsConsumer[test.queue2]

received response   ## this getting printed here meaning that the file endpoint do not respect the INOUT exchangepattern.

Going for sleep sleepid=3,  thread=Camel (camel-1) thread #2 - file://test    

Done sleep sleepid=3,  thread=Camel (camel-1) thread #2 - file://test

If we observe the execution output we will see that received response gets printed before the completion of route starting with FILE ENDPOINT.

This shows that the file endpoint did not understood that the exchange is a INOUT exchange


pictorial representation:(click image to enlarge)

enter image description here

like image 263
Bhuvan Avatar asked Sep 20 '15 14:09

Bhuvan


People also ask

How does Camel exchange work?

The rule Camel uses is to take the out Message produced by the previous Processor and set it as the in for the next Processor . If the previous Processor did not produce an out, then the in of the previous Processor is sent as the next in.

What is exchange property in Camel?

An Exchange property is a key/value set as a Map on the org. apache. camel. Exchange instance. This is not for setting property placeholders.

What are the various message exchange patterns?

The three basic message exchange patterns. Top to bottom: datagram, request-response, and duplex. Each of these MEPs can also support sessions.


1 Answers

Yes. Not all camel endpoints support INOUT. The JMS endpoint supports it but the file endpoint does not.

Unfortunately this is indeed not well documented.

like image 56
Christian Schneider Avatar answered Oct 23 '22 05:10

Christian Schneider