You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/06/08 13:27:09 UTC
[camel] 04/04: CAMEL-16627: camel-core - Add common header for
source timestamp
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 a9deb523db39907b1820f08ab7bf9a4d53ad16c0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jun 8 15:26:08 2021 +0200
CAMEL-16627: camel-core - Add common header for source timestamp
---
.../org/apache/camel/catalog/docs/simple-language.adoc | 8 ++++++++
.../src/main/java/org/apache/camel/Message.java | 8 ++++----
.../docs/modules/languages/pages/simple-language.adoc | 8 ++++++++
.../language/simple/ast/SimpleFunctionExpression.java | 4 ++++
.../org/apache/camel/language/simple/SimpleTest.java | 6 ++++++
.../apache/camel/support/builder/ExpressionBuilder.java | 16 ++++++++++++++++
.../modules/languages/pages/simple-language.adoc | 8 ++++++++
7 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/simple-language.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/simple-language.adoc
index f981dec..01e4dc3 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/simple-language.adoc
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/simple-language.adoc
@@ -82,6 +82,14 @@ OGNL expression.
|id |String |the input message id
+|messageTimestamp |String |the input message timestamp (millis since epoc) that this message originates from.
+Some systems like JMS, Kafka, AWS have a timestamp on the event/message, that Camel received. This method returns
+the timestamp, if a timestamp exists.
+The message timestamp and exchange created are not the same. An exchange always have a created timestamp which is the
+local timestamp when Camel created the exchange. The message timestamp is only available in some Camel components
+when the consumer is able to extract the timestamp from the source event.
+If the message has no timestamp then 0 is returned.
+
|body |Object |the input body
|in.body |Object |*deprecated* the input body
diff --git a/core/camel-api/src/main/java/org/apache/camel/Message.java b/core/camel-api/src/main/java/org/apache/camel/Message.java
index 0164405..3a748fe 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Message.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Message.java
@@ -58,12 +58,12 @@ public interface Message {
* Some systems like JMS, Kafka, AWS have a timestamp on the event/message, that Camel received. This method returns
* the timestamp, if a timestamp exists.
* <p/>
- * The message timestamp and exchange created are not the same. An exchange always have a created timestamp which is the
- * local timestamp when Camel created the exchange. The message timestamp is only available in some Camel components
- * when the consumer is able to extract the timestamp from the source event.
+ * The message timestamp and exchange created are not the same. An exchange always have a created timestamp which is
+ * the local timestamp when Camel created the exchange. The message timestamp is only available in some Camel
+ * components when the consumer is able to extract the timestamp from the source event.
*
* @return the timestamp, or <tt>0</tt> if the message has no source timestamp.
- * @see Exchange#getCreated()
+ * @see Exchange#getCreated()
*/
long getMessageTimestamp();
diff --git a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
index f981dec..01e4dc3 100644
--- a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
+++ b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
@@ -82,6 +82,14 @@ OGNL expression.
|id |String |the input message id
+|messageTimestamp |String |the input message timestamp (millis since epoc) that this message originates from.
+Some systems like JMS, Kafka, AWS have a timestamp on the event/message, that Camel received. This method returns
+the timestamp, if a timestamp exists.
+The message timestamp and exchange created are not the same. An exchange always have a created timestamp which is the
+local timestamp when Camel created the exchange. The message timestamp is only available in some Camel components
+when the consumer is able to extract the timestamp from the source event.
+If the message has no timestamp then 0 is returned.
+
|body |Object |the input body
|in.body |Object |*deprecated* the input body
diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index 5212c57..21993f5 100644
--- a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -416,6 +416,8 @@ public class SimpleFunctionExpression extends LiteralExpression {
return ExpressionBuilder.bodyOneLine();
} else if (ObjectHelper.equal(expression, "id")) {
return ExpressionBuilder.messageIdExpression();
+ } else if (ObjectHelper.equal(expression, "messageTimestamp")) {
+ return ExpressionBuilder.messageTimestampExpression();
} else if (ObjectHelper.equal(expression, "exchangeId")) {
return ExpressionBuilder.exchangeIdExpression();
} else if (ObjectHelper.equal(expression, "exchange")) {
@@ -774,6 +776,8 @@ public class SimpleFunctionExpression extends LiteralExpression {
return "bodyOneLine(exchange)";
} else if (ObjectHelper.equal(expression, "id")) {
return "message.getMessageId()";
+ } else if (ObjectHelper.equal(expression, "messageTimestamp")) {
+ return "message.getMessageTimestamp()";
} else if (ObjectHelper.equal(expression, "exchangeId")) {
return "exchange.getExchangeId()";
} else if (ObjectHelper.equal(expression, "exchange")) {
diff --git a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index a7e7b8c..5036876 100644
--- a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -1951,6 +1951,12 @@ public class SimpleTest extends LanguageTestSupport {
assertExpression(exp, "99");
}
+ @Test
+ public void testMessageTimestamp() throws Exception {
+ exchange.getIn().setHeader(Exchange.MESSAGE_TIMESTAMP, 1234L);
+ assertExpression("${messageTimestamp}", 1234L);
+ }
+
@Override
protected String getLanguageName() {
return "simple";
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
index ac839be..9951a5b 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/builder/ExpressionBuilder.java
@@ -1591,6 +1591,22 @@ public class ExpressionBuilder {
}
/**
+ * Returns an Expression for the inbound message timestamp
+ */
+ public static Expression messageTimestampExpression() {
+ return new ExpressionAdapter() {
+ public Object evaluate(Exchange exchange) {
+ return exchange.getIn().getMessageTimestamp();
+ }
+
+ @Override
+ public String toString() {
+ return "messageTimestamp";
+ }
+ };
+ }
+
+ /**
* Returns an Expression for the exchange id
*/
public static Expression exchangeIdExpression() {
diff --git a/docs/components/modules/languages/pages/simple-language.adoc b/docs/components/modules/languages/pages/simple-language.adoc
index a4ac7c3..8ec77dc 100644
--- a/docs/components/modules/languages/pages/simple-language.adoc
+++ b/docs/components/modules/languages/pages/simple-language.adoc
@@ -84,6 +84,14 @@ OGNL expression.
|id |String |the input message id
+|messageTimestamp |String |the input message timestamp (millis since epoc) that this message originates from.
+Some systems like JMS, Kafka, AWS have a timestamp on the event/message, that Camel received. This method returns
+the timestamp, if a timestamp exists.
+The message timestamp and exchange created are not the same. An exchange always have a created timestamp which is the
+local timestamp when Camel created the exchange. The message timestamp is only available in some Camel components
+when the consumer is able to extract the timestamp from the source event.
+If the message has no timestamp then 0 is returned.
+
|body |Object |the input body
|in.body |Object |*deprecated* the input body