You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2024/06/26 14:47:32 UTC
(camel-quarkus) branch main updated: Document that ConsumerTemplate, ProducerTemplate & Registry can be injected into CDI beans
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new d8a15e06b7 Document that ConsumerTemplate, ProducerTemplate & Registry can be injected into CDI beans
d8a15e06b7 is described below
commit d8a15e06b76176062e09dbb2e851784d8dd8c5a9
Author: James Netherton <ja...@gmail.com>
AuthorDate: Wed Jun 26 15:09:13 2024 +0100
Document that ConsumerTemplate, ProducerTemplate & Registry can be injected into CDI beans
---
docs/modules/ROOT/pages/user-guide/cdi.adoc | 58 +++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/docs/modules/ROOT/pages/user-guide/cdi.adoc b/docs/modules/ROOT/pages/user-guide/cdi.adoc
index 6170b50428..eacd9157a1 100644
--- a/docs/modules/ROOT/pages/user-guide/cdi.adoc
+++ b/docs/modules/ROOT/pages/user-guide/cdi.adoc
@@ -65,6 +65,64 @@ public class MyBean {
}
----
+== `ProducerTemplate` and `ConsumerTemplate`
+
+If you want to use `ProducerTemplate` or `ConsumerTemplate`, then they can be injected into beans.
+
+[source,java]
+----
+import jakarta.inject.Inject;
+import jakarta.enterprise.context.ApplicationScoped;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.ProducerTemplate;
+
+@ApplicationScoped
+public class MyBean {
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ @Inject
+ FluentProducerTemplate fluentProducerTemplate;
+
+ @Inject
+ ConsumerTemplate consumerTemplate;
+
+ public String produceToDirectEndpoint() {
+ return producerTemplate.requestBody("direct:start", "Hello World", String.class);
+ }
+
+ public String produceToDirectEndpointFluently() {
+ return fluentProducerTemplate.to("direct:start").withBody("Hello World").request(String.class);
+ }
+
+ public String consumeFromJMSEndpoint() {
+ return consumerTemplate.receiveBody("jms:queue:camel", String.class);
+ }
+}
+----
+
+== Accessing the Camel Registry
+
+The Camel registry can be injected into beans.
+
+[source,java]
+----
+import jakarta.inject.Inject;
+import jakarta.enterprise.context.ApplicationScoped;
+import org.apache.camel.spi.Registry;
+
+@ApplicationScoped
+public class MyBean {
+ @Inject
+ Registry registry;
+
+ public CoolBean lookupBean() {
+ return registry.lookupByNameAndType("coolBean", CoolBean.class);
+ }
+}
+----
+
== `@EndpointInject` and `@Produce`
If you are used to `@org.apache.camel.EndpointInject` and `@org.apache.camel.Produce` from