This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 66bd70dd2159ca1e87759651827c8b6d4a1a9322 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Aug 18 16:05:26 2021 +0200 Polish and cleanup documentation --- .../java/org/apache/camel/ConsumerTemplate.java | 13 ++---------- .../modules/ROOT/pages/consumertemplate.adoc | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/core/camel-api/src/main/java/org/apache/camel/ConsumerTemplate.java b/core/camel-api/src/main/java/org/apache/camel/ConsumerTemplate.java index 5c4d04e..08e29fb 100644 --- a/core/camel-api/src/main/java/org/apache/camel/ConsumerTemplate.java +++ b/core/camel-api/src/main/java/org/apache/camel/ConsumerTemplate.java @@ -28,19 +28,10 @@ package org.apache.camel; * <p/> * <b>All</b> methods throws {@link RuntimeCamelException} if consuming of the {@link Exchange} failed and an Exception * occurred. The <tt>getCause</tt> method on {@link RuntimeCamelException} returns the wrapper original caused - * exception. <br/> - * <p/> - * All the receive<b>Body</b> methods will return the content according to this strategy - * <ul> - * <li>throws {@link RuntimeCamelException} as stated above</li> - * <li>The <tt>fault.body</tt> if there is a fault message set and its not <tt>null</tt></li> - * <li>The <tt>out.body</tt> if there is a out message set and its not <tt>null</tt></li> - * <li>The <tt>in.body</tt></li> - * </ul> - * <br/> + * exception. * <p/> * Before using the template it must be started. And when you are done using the template, make sure to {@link #stop()} - * the template. <br/> + * the template. * <p/> * <b>Important note on usage:</b> See this * <a href="http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html">FAQ entry</a> before diff --git a/docs/user-manual/modules/ROOT/pages/consumertemplate.adoc b/docs/user-manual/modules/ROOT/pages/consumertemplate.adoc index b35cc5e..73ae127 100644 --- a/docs/user-manual/modules/ROOT/pages/consumertemplate.adoc +++ b/docs/user-manual/modules/ROOT/pages/consumertemplate.adoc @@ -23,6 +23,29 @@ Object body = template.receiveBody(); body = template.receiveBody("activemq:MyQueue"); ---- +== Receive modes + +The consumer template operates in three modes: + +- **receive** - Consumes from the endpoint, waiting until there is a message (can potentially wait for a long time!). +- **receiveNoWait** - Consumes from endpoint, not waiting for a message if none exists. +- **receiveTimeout** - Consumes from the endpoint, waiting until there is a response, or the timeout occurs. + +In the previous examples then it was the first mode we used (`receiveBody`). +For example if there are no messages on the `activemq:MyQueue` then Camel would wait until a message is sent to this queue. + +Often you dont want to wait _forever_ so its often a good idea to use a timeout value, such as 5 seconds: + +[source,java] +---- +ConsumerTemplate template = exchange.getContext().createConsumerTemplate(); + +// receive from a specific queue +body = template.receiveBody("activemq:MyQueue", 5000); +---- + +Here we wait at most 5 seconds for a message to be consumed, if there was no message, then `null` is returned as response. + == See Also See xref:producertemplate.adoc[ProducerTemplate] \ No newline at end of file