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 2020/01/24 10:30:48 UTC
[camel] branch master updated: CAMEL-14433: Optimize core -
MessageID is now by default the same as exchange ID.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 4f04c2e CAMEL-14433: Optimize core - MessageID is now by default the same as exchange ID.
4f04c2e is described below
commit 4f04c2ebf9b09e20651eb8c0616809a8e42bea3e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 24 11:30:09 2020 +0100
CAMEL-14433: Optimize core - MessageID is now by default the same as exchange ID.
---
.../src/main/java/org/apache/camel/Message.java | 7 ++++++-
.../java/org/apache/camel/impl/MessageSupportTest.java | 17 ++++++++++++++---
.../java/org/apache/camel/support/MessageSupport.java | 12 +++++-------
.../modules/ROOT/pages/camel-3x-upgrade-guide.adoc | 6 ++++++
4 files changed, 31 insertions(+), 11 deletions(-)
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 b1f3745..4cc3102 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
@@ -33,7 +33,12 @@ import org.apache.camel.spi.HeadersMapFactory;
public interface Message {
/**
- * Returns the id of the message
+ * Returns the id of the message.
+ * <p/>
+ * By default the message uses the same id as {@link Exchange#getExchangeId()} as messages are associated with the exchange
+ * and using different IDs does not offer much value. Another reason is to optimize for performance to avoid generating new IDs.
+ * <p/>
+ * A few Camel components do provide their own message IDs such as the JMS components.
*
* @return the message id
*/
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
index 4ecf911..7d0ba92 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
@@ -56,19 +56,30 @@ public class MessageSupportTest extends ContextTestSupport {
}
@Test
- public void testGetMessageId() {
+ public void testGetMessageIdWithGenerator() {
context.setUuidGenerator(new SimpleUuidGenerator());
Exchange exchange = new DefaultExchange(context);
Message in = exchange.getIn();
+ // they should use the same id
assertEquals("1", in.getMessageId());
+ assertEquals("1", in.getExchange().getExchangeId());
+ }
+
+ @Test
+ public void testGetMessageId() {
+ Exchange exchange = new DefaultExchange(context);
+ Message in = exchange.getIn();
+
+ // they should use the same id
+ assertSame(in.getExchange().getExchangeId(), in.getMessageId());
}
@Test
public void testGetMessageIdWithoutAnExchange() {
Message in = new DefaultMessage(context);
-
- assertNotNull(in.getMessageId());
+ // there are no exchange so its null
+ assertNull(in.getMessageId());
}
@Test
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/MessageSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/MessageSupport.java
index 4edb4b3..c3ae4ef 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/MessageSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/MessageSupport.java
@@ -284,14 +284,12 @@ public abstract class MessageSupport implements Message, CamelContextAware, Data
* Allow implementations to auto-create a messageId
*/
protected String createMessageId() {
- String uuid = null;
if (exchange != null) {
- uuid = exchange.getContext().getUuidGenerator().generateUuid();
+ // optimize and reuse exchange id
+ return exchange.getExchangeId();
+ } else {
+ return null;
}
- // fall back to the simple UUID generator
- if (uuid == null) {
- uuid = new SimpleUuidGenerator().generateUuid();
- }
- return uuid;
}
+
}
diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
index ca6dbe4..7969a8a 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc
@@ -171,6 +171,12 @@ You can use these methods by adapting to the extended exchange as shown below:
exchange.adapt(ExtendedExchange.class).addOnCompletion(...);
----
+==== Message
+
+The message ID will now default to use the same id as Exchange ID as messages are associated with the exchange
+and using different IDs does not offer much value. Another reason is to optimize for performance to avoid generating new IDs.
+A few Camel components do provide their own message IDs such as the JMS components.
+
==== UnitOfWork
For advanced Camel users whom implement custom `UnitOfWork` should implement the new `isBeforeAfterProcess()' method and return true of false,