Request ReplyCamel 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 actions
Explicitly specifying InOutWhen 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 You can specify the exchange pattern in DSL rule or Spring configuration. // Send to an endpoint using InOut from("direct:testInOut").inOut("mock:result"); // Send to an endpoint using InOut from("direct:testInOnly").inOnly("mock:result"); // Set the exchange pattern to InOut, then send it from direct:inOnly to mock:result endpoint from("direct:testSetToInOnlyThenTo") .setExchangePattern(ExchangePattern.InOnly) .to("mock:result"); from("direct:testSetToInOutThenTo") .setExchangePattern(ExchangePattern.InOut) .to("mock:result"); // Or we can pass the pattern as a parameter to the to() method from("direct:testToWithInOnlyParam").to(ExchangePattern.InOnly, "mock:result"); from("direct:testToWithInOutParam").to(ExchangePattern.InOut, "mock:result"); from("direct:testToWithRobustInOnlyParam").to(ExchangePattern.RobustInOnly, "mock:result"); // Set the exchange pattern to InOut, then send it on from("direct:testSetExchangePatternInOnly") .setExchangePattern(ExchangePattern.InOnly).to("mock:result"); <camelContext xmlns="http://camel.apache.org/schema/spring"> <!-- Send the exchange as InOnly --> <route> <from uri="direct:testInOut"/> <inOut uri="mock:result"/> </route> <!-- Send the exchange as InOnly --> <route> <from uri="direct:testInOnly"/> <inOnly uri="mock:result"/> </route> <!-- lets set the exchange pattern then send it on --> <route> <from uri="direct:testSetToInOnlyThenTo"/> <setExchangePattern pattern="InOnly"/> <to uri="mock:result"/> </route> <route> <from uri="direct:testSetToInOutThenTo"/> <setExchangePattern pattern="InOut"/> <to uri="mock:result"/> </route> <route> <from uri="direct:testSetExchangePatternInOnly"/> <setExchangePattern pattern="InOnly"/> <to uri="mock:result"/> </route> <!-- Lets pass the pattern as an argument in the to element --> <route> <from uri="direct:testToWithInOnlyParam"/> <to uri="mock:result" pattern="InOnly"/> </route> <route> <from uri="direct:testToWithInOutParam"/> <to uri="mock:result" pattern="InOut"/> </route> <route> <from uri="direct:testToWithRobustInOnlyParam"/> <to uri="mock:result" pattern="RobustInOnly"/> </route> </camelContext> Using This PatternIf 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. |
