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
The following commit(s) were added to refs/heads/main by this push: new 34aecbd Polish and cleanup documentation 34aecbd is described below commit 34aecbd7156c7ca4e04b52821ec894743a3b8ded Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Aug 11 16:31:04 2021 +0200 Polish and cleanup documentation --- .../modules/ROOT/pages/pojo-producing.adoc | 69 ++++++++++++---------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/docs/user-manual/modules/ROOT/pages/pojo-producing.adoc b/docs/user-manual/modules/ROOT/pages/pojo-producing.adoc index 0601d90..30bc54e 100644 --- a/docs/user-manual/modules/ROOT/pages/pojo-producing.adoc +++ b/docs/user-manual/modules/ROOT/pages/pojo-producing.adoc @@ -1,20 +1,22 @@ = POJO producing There are two different ways to send messages to any Camel -xref:endpoint.adoc[Endpoint] from a POJO. +xref:endpoint.adoc[Endpoint] from a POJO: -[[POJOProducing-EndpointInject]] -== Via `@EndpointInject` +- Using `@Produce` or `@EndpointInject` +- Or to hide using an interface -To allow sending of messages from POJOs you can use the `org.apache.camel.EndpointInject` annotation. -This will inject a `org.apache.camel.ProducerTemplate` so that the bean can participate in message exchanges. +== Using @Produce -Example: Send a message to the *`foo.bar`* ActiveMQ queue: +To allow sending of messages from POJOs you can use the `@Produce` annotation. +This will inject a `org.apache.camel.ProducerTemplate` so that the bean can send messages. + +For example to send a message to the foo queue on ActiveMQ: [source,java] ---- public class Foo { - @EndpointInject("activemq:foo.bar") + @Produce("activemq:foo") ProducerTemplate producer; public void doSomething() { @@ -26,29 +28,25 @@ public class Foo { ---- The downside of this is that your code is now dependent on a Camel API, -the *`ProducerTemplate`*. The next section describes how to remove this +the `ProducerTemplate`. The next section describes how to remove this dependency. -[TIP] -==== - -See xref:pojo-consuming.adoc[POJO Consuming] for how to use a property -on the bean as endpoint configuration, e.g., using the *`property`* -attribute on *`@Produce`*, *`@EndpointInject`*. - -==== +TIP: See xref:pojo-consuming.adoc[POJO Consuming] for how to use a property +on the bean as endpoint configuration, e.g., using the `property` +attribute on `@Produce` or `@EndpointInject`. -[[POJOProducing-HidingtheCamelAPIsFromYourCodeUsingProduce]] -== Hiding the Camel APIs From Your Code Using `@Produce` +== Hiding the Camel APIs From Your Code -You can hide Camel APIs from your application code so the next option might -be more suitable. You can add the *`@Produce`* annotation to an injection -point (a field or property setter) using a *`ProducerTemplate`* *or* -using some interface you use in your business logic. Example: +You can hide Camel APIs from your application code. +You can add the `@Produce` annotation to an injection +point (a field or property setter) using some interface +you use in your business logic. Example: [source,java] ---- public interface MyListener { + // this method is request/reply (InOut) because the method has a return value + // to use one way (InOnly) then the method should be a void method String sayHello(String name); } @@ -57,18 +55,27 @@ public class MyBean { protected MyListener producer; public void doSomething() { - // lets send a message + // lets send a message and get a response back String response = producer.sayHello("James"); } } ---- Here Camel will automatically inject a smart client side proxy at -the *`@Produce`* annotation - an instance of the *`MyListener`* -instance. When we invoke methods on this interface the method call is -turned into an object and it is sent to the -endpoint - in this case the xref:components::activemq-component.adoc[ActiveMQ] endpoint to -queue *`foo`*; then the caller blocks for a response. - -If you want to make asynchronous message sends then use an -xref:using-exchange-pattern-annotations.adoc[@InOnly] annotation on the injection point. +the `@Produce` annotation - an instance of the `MyListener` +interface. + +When we invoke methods on this interface the method call is +turned into an object and is sent to the +endpoint; in this case the xref:components::activemq-component.adoc[ActiveMQ] endpoint to +queue *`foo`*. Because the `sayHello` method has a return type (`String`) then Camel +will use xref:{eip-vc}:eips:requestReply-eip.adoc[Request Reply] (InOut) messaging. + +[source,java] +---- +public interface MyListener { + void sayHello(String name); +} +---- + +If the method is a `void` method, then Camel will use xref:{eip-vc}:eips:event-message.adoc[Event Message] (InOnly) messaging.