You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/03/30 16:37:42 UTC

[camel] 07/16: CAMEL-17792: Add doc about the message headers of camel-jgroups

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-17792/doc-message-headers
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 1046d09aed3aea5afd15fb69daae4de091442cef
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Wed Mar 30 12:04:31 2022 +0200

    CAMEL-17792: Add doc about the message headers of camel-jgroups
---
 .../apache/camel/component/jgroups/jgroups.json    |  6 +++
 .../src/main/docs/jgroups-component.adoc           | 24 ++----------
 .../component/jgroups/CamelJGroupsReceiver.java    |  2 +-
 .../camel/component/jgroups/JGroupsConstants.java  | 45 ++++++++++++++++++++++
 .../camel/component/jgroups/JGroupsEndpoint.java   | 15 +++-----
 .../camel/component/jgroups/JGroupsFilters.java    |  2 +-
 .../camel/component/jgroups/JGroupsProducer.java   |  4 +-
 .../component/jgroups/JGroupsConsumerTest.java     |  2 +-
 8 files changed, 64 insertions(+), 36 deletions(-)

diff --git a/components/camel-jgroups/src/generated/resources/org/apache/camel/component/jgroups/jgroups.json b/components/camel-jgroups/src/generated/resources/org/apache/camel/component/jgroups/jgroups.json
index e3a989f..0aad329 100644
--- a/components/camel-jgroups/src/generated/resources/org/apache/camel/component/jgroups/jgroups.json
+++ b/components/camel-jgroups/src/generated/resources/org/apache/camel/component/jgroups/jgroups.json
@@ -29,6 +29,12 @@
     "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...]
     "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...]
   },
+  "headers": {
+    "JGROUPS_CHANNEL_ADDRESS": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "org.jgroups.Address", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Address (`org.jgroups.Address`) of the channel associated with the\nendpoint." },
+    "JGROUPS_DEST": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "org.jgroups.Address", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "*Consumer*: The `org.jgroups.Address` instance extracted by\n`org.jgroups.Message`.getDest() method of the consumed message.\n*Producer*: The custom destination `org.jgroups.Address` of the message to be sent." },
+    "JGROUPS_SRC": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "org.jgroups.Address", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "*Consumer* : The `org.jgroups.Address` instance extracted by\n`org.jgroups.Message`.getSrc() method of the consumed message. \n*Producer*: The custom source `org.jgroups.Address` of the message to be sent." },
+    "JGROUPS_ORIGINAL_MESSAGE": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "org.jgroups.Message", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The original `org.jgroups.Message` instance from which the body of the\nconsumed message has been extracted." }
+  },
   "properties": {
     "clusterName": { "kind": "path", "displayName": "Cluster Name", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The name of the JGroups cluster the component should connect to." },
     "channelProperties": { "kind": "parameter", "displayName": "Channel Properties", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Specifies configuration properties of the JChannel used by the endpoint." },
diff --git a/components/camel-jgroups/src/main/docs/jgroups-component.adoc b/components/camel-jgroups/src/main/docs/jgroups-component.adoc
index 390b618..06cbaf5 100644
--- a/components/camel-jgroups/src/main/docs/jgroups-component.adoc
+++ b/components/camel-jgroups/src/main/docs/jgroups-component.adoc
@@ -53,28 +53,10 @@ include::partial$component-endpoint-options.adoc[]
 
 // endpoint options: END
 
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
 
-== Headers
-
-[width="100%",cols="10%,10%,70%",options="header",]
-|=======================================================================
-|Header |Constant |Description
-
-|`JGROUPS_ORIGINAL_MESSAGE` |`JGroupsEndpoint.HEADER_JGROUPS_ORIGINAL_MESSAGE` |The original `org.jgroups.Message` instance from which the body of the
-consumed message has been extracted.
-
-|`JGROUPS_SRC` |`JGroupsEndpoint.`HEADER_JGROUPS_SRC |*Consumer* : The `org.jgroups.Address` instance extracted by
-`org.jgroups.Message`.getSrc() method of the consumed message. 
-*Producer*: The custom source `org.jgroups.Address` of the message to be sent.
-
-|`JGROUPS_DEST` |`JGroupsEndpoint.`HEADER_JGROUPS_DEST |*Consumer*: The `org.jgroups.Address` instance extracted by
-`org.jgroups.Message`.getDest() method of the consumed message.
-*Producer*: The custom destination `org.jgroups.Address` of the message to be sent.
-
-|`JGROUPS_CHANNEL_ADDRESS` |`JGroupsEndpoint.`HEADER_JGROUPS_CHANNEL_ADDRESS |Address (`org.jgroups.Address`) of the channel associated with the
-endpoint.
-|=======================================================================
- 
 == Usage
 
 Using `jgroups` component on the consumer side of the route will capture
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/CamelJGroupsReceiver.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/CamelJGroupsReceiver.java
index 4383903..ad644e3 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/CamelJGroupsReceiver.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/CamelJGroupsReceiver.java
@@ -27,7 +27,7 @@ import org.jgroups.View;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.camel.component.jgroups.JGroupsEndpoint.HEADER_JGROUPS_CHANNEL_ADDRESS;
+import static org.apache.camel.component.jgroups.JGroupsConstants.HEADER_JGROUPS_CHANNEL_ADDRESS;
 
 /**
  * Implementation of JGroups message receiver ({@code org.jgroups.Receiver}) wrapping incoming messages into Camel
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsConstants.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsConstants.java
new file mode 100644
index 0000000..9cf875b
--- /dev/null
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsConstants.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jgroups;
+
+import org.apache.camel.spi.Metadata;
+
+public final class JGroupsConstants {
+
+    @Metadata(description = "Address (`org.jgroups.Address`) of the channel associated with the\n" +
+                            "endpoint.",
+              javaType = "org.jgroups.Address")
+    public static final String HEADER_JGROUPS_CHANNEL_ADDRESS = "JGROUPS_CHANNEL_ADDRESS";
+    @Metadata(description = "*Consumer*: The `org.jgroups.Address` instance extracted by\n" +
+                            "`org.jgroups.Message`.getDest() method of the consumed message.\n" +
+                            "*Producer*: The custom destination `org.jgroups.Address` of the message to be sent.",
+              javaType = "org.jgroups.Address")
+    public static final String HEADER_JGROUPS_DEST = "JGROUPS_DEST";
+    @Metadata(description = "*Consumer* : The `org.jgroups.Address` instance extracted by\n" +
+                            "`org.jgroups.Message`.getSrc() method of the consumed message. \n" +
+                            "*Producer*: The custom source `org.jgroups.Address` of the message to be sent.",
+              javaType = "org.jgroups.Address")
+    public static final String HEADER_JGROUPS_SRC = "JGROUPS_SRC";
+    @Metadata(description = "The original `org.jgroups.Message` instance from which the body of the\n" +
+                            "consumed message has been extracted.",
+              javaType = "org.jgroups.Message")
+    public static final String HEADER_JGROUPS_ORIGINAL_MESSAGE = "JGROUPS_ORIGINAL_MESSAGE";
+
+    private JGroupsConstants() {
+
+    }
+}
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java
index 6d6ab0a..b7ae967 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsEndpoint.java
@@ -39,14 +39,9 @@ import org.slf4j.LoggerFactory;
  * Exchange messages with JGroups clusters.
  */
 @UriEndpoint(firstVersion = "2.13.0", scheme = "jgroups", title = "JGroups", syntax = "jgroups:clusterName",
-             category = { Category.CLUSTERING, Category.MESSAGING })
+             category = { Category.CLUSTERING, Category.MESSAGING }, headersClass = JGroupsConstants.class)
 public class JGroupsEndpoint extends DefaultEndpoint {
 
-    public static final String HEADER_JGROUPS_ORIGINAL_MESSAGE = "JGROUPS_ORIGINAL_MESSAGE";
-    public static final String HEADER_JGROUPS_SRC = "JGROUPS_SRC";
-    public static final String HEADER_JGROUPS_DEST = "JGROUPS_DEST";
-    public static final String HEADER_JGROUPS_CHANNEL_ADDRESS = "JGROUPS_CHANNEL_ADDRESS";
-
     private static final Logger LOG = LoggerFactory.getLogger(JGroupsEndpoint.class);
     private AtomicInteger connectCount = new AtomicInteger();
 
@@ -84,9 +79,9 @@ public class JGroupsEndpoint extends DefaultEndpoint {
 
     public Exchange createExchange(Message message) {
         Exchange exchange = createExchange();
-        exchange.getIn().setHeader(HEADER_JGROUPS_ORIGINAL_MESSAGE, message);
-        exchange.getIn().setHeader(HEADER_JGROUPS_SRC, message.getSrc());
-        exchange.getIn().setHeader(HEADER_JGROUPS_DEST, message.getDest());
+        exchange.getIn().setHeader(JGroupsConstants.HEADER_JGROUPS_ORIGINAL_MESSAGE, message);
+        exchange.getIn().setHeader(JGroupsConstants.HEADER_JGROUPS_SRC, message.getSrc());
+        exchange.getIn().setHeader(JGroupsConstants.HEADER_JGROUPS_DEST, message.getDest());
         exchange.getIn().setBody(message.getObject());
         return exchange;
     }
@@ -100,7 +95,7 @@ public class JGroupsEndpoint extends DefaultEndpoint {
     @Override
     public Exchange createExchange() {
         Exchange exchange = super.createExchange();
-        exchange.getIn().setHeader(HEADER_JGROUPS_CHANNEL_ADDRESS, resolvedChannel.getAddress());
+        exchange.getIn().setHeader(JGroupsConstants.HEADER_JGROUPS_CHANNEL_ADDRESS, resolvedChannel.getAddress());
         return exchange;
     }
 
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsFilters.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsFilters.java
index caf4e6a..b6f4f67 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsFilters.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsFilters.java
@@ -23,7 +23,7 @@ import org.jgroups.View;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.camel.component.jgroups.JGroupsEndpoint.HEADER_JGROUPS_CHANNEL_ADDRESS;
+import static org.apache.camel.component.jgroups.JGroupsConstants.HEADER_JGROUPS_CHANNEL_ADDRESS;
 
 /**
  * JGroups-specific filters factory.
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java
index 7fe3736..b927af2 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsProducer.java
@@ -65,8 +65,8 @@ public class JGroupsProducer extends DefaultProducer {
     public void process(Exchange exchange) throws Exception {
         Object body = exchange.getIn().getBody();
         if (body != null) {
-            Address destinationAddress = exchange.getIn().getHeader(JGroupsEndpoint.HEADER_JGROUPS_DEST, Address.class);
-            Address sourceAddress = exchange.getIn().getHeader(JGroupsEndpoint.HEADER_JGROUPS_SRC, Address.class);
+            Address destinationAddress = exchange.getIn().getHeader(JGroupsConstants.HEADER_JGROUPS_DEST, Address.class);
+            Address sourceAddress = exchange.getIn().getHeader(JGroupsConstants.HEADER_JGROUPS_SRC, Address.class);
 
             LOG.debug("Posting: {} to cluster: {}", body, clusterName);
             if (destinationAddress != null) {
diff --git a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java
index 96d9746..83a2eae 100644
--- a/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java
+++ b/components/camel-jgroups/src/test/java/org/apache/camel/component/jgroups/JGroupsConsumerTest.java
@@ -25,7 +25,7 @@ import org.jgroups.Message;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 
-import static org.apache.camel.component.jgroups.JGroupsEndpoint.HEADER_JGROUPS_ORIGINAL_MESSAGE;
+import static org.apache.camel.component.jgroups.JGroupsConstants.HEADER_JGROUPS_ORIGINAL_MESSAGE;
 
 public class JGroupsConsumerTest extends CamelTestSupport {