Request Reply has been edited by willem jiang (Dec 10, 2008).

Change summary:

CAMEL-1181

(View changes)

Content:

Request Reply

Camel supports the Request Reply from the EIP patterns by supporting the Exchange Pattern on a Message which can be set to InOut to indicate a request/reply. Camel Components then implement this pattern using the underlying transport or protocols.

For example when using JMS with InOut the component will by default perform these acxtions

  • create by default a temporary inbound queue
  • set the JMSReplyTo destination on the request message
  • set the JMSCorrelationID on the request message
  • send the request message
  • consume the response and associate the inbound message to the request using the JMSCorrelationID (as you may be performing many concurrent request/responses).

Explicitly specifying InOut

When consuming messages from JMS a Request-Reply is indicated by the presence of the JMSReplyTo header.

You can explicitly force an endpoint to be in Request Reply mode by setting the exchange pattern on the URI. e.g.

jms:MyQueue?exchangePattern=InOut

NOTE
>From Camel 1.5.1 you can specify the exchange pattern in DSL rule or Spring configuration.


//Set the exchange pattern to InOut, then send it from direct:inOnly to mock:result endpoint
from("direct:inOnly").inOut().to("mock:result");
//Set the exchange pattern to InOut, then send it from direct:inOut to mock:result endpoint               
from("direct:inOut").setExchangePattern(ExchangePattern.InOnly).to("mock:result");
//Send the exchange from direct:inOut1 to mock:result with setting the exchange pattern to be RobustInOnly
from("direct:inOut1").to("mock:result", ExchangePattern.RobustInOnly);
//Send the exchange from direct:inOut2 to mock:result with setting the exchange pattern to be InOnly
from("direct:inOut2").inOnly("mock:result");
<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
  <!-- Set the exchange pattern to InOut, then send it from direct:inOnly to mock:result endpoint -->
  <route>
    <from uri="direct:inOnly"/>
    <setExchangePattern pattern="InOut"/>      	
    <to uri="mock:result"/>      
  </route>

  <!-- Set the exchange pattern to InOnly, then send it from direct:inOut to mock:result endpoint -->
  <route>
    <from uri="direct:inOut"/>
    <setExchangePattern pattern="InOnly"/>
    <to uri="mock:result"/> 
  </route>
  
  <!-- Send the exchange from direct:inOut1 to mock:result with setting the exchange pattern to be RobustInOnly-->
  <route>
    <from uri="direct:inOut1"/>
    <to uri="mock:result" pattern="RobustInOnly"/>
  </route>
  
  <!-- Send the exchange from direct:inOut2 to mock:result with setting the exchange pattern to be InOnly -->
  <route>
    <from uri="direct:inOut2"/>
    <inOnly uri="mock:result"/>
  </route>
 </camelContext>

Using This Pattern

If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out.

Reply via email to