diff --git a/spring-integration-core/src/main/java/org/springframework/integration/message/GenericMessage.java b/spring-integration-core/src/main/java/org/springframework/integration/message/GenericMessage.java index 65cebaeede..24464a3cd9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/message/GenericMessage.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/message/GenericMessage.java @@ -19,6 +19,8 @@ package org.springframework.integration.message; import java.util.concurrent.locks.ReentrantLock; import org.springframework.integration.SystemInterruptedException; +import org.springframework.integration.util.RandomGuidUidGenerator; +import org.springframework.integration.util.UidGenerator; import org.springframework.util.Assert; /** @@ -34,9 +36,17 @@ public class GenericMessage implements Message { private T payload; + private UidGenerator defaultUidGenerator = new RandomGuidUidGenerator(); + private ReentrantLock lock; + /** + * Create a new message with the given id and payload. + * + * @param id unique identifier for this message + * @param payload the message payload + */ public GenericMessage(Object id, T payload) { Assert.notNull(id, "id must not be null"); Assert.notNull(payload, "payload must not be null"); @@ -44,6 +54,19 @@ public class GenericMessage implements Message { this.payload = payload; } + /** + * Create a new message with the given payload. The id will be generated by + * the default {@link UidGenerator} strategy. + * + * @param payload the message payload + */ + public GenericMessage(T payload) { + Assert.notNull(payload, "payload must not be null"); + this.id = this.defaultUidGenerator.generateUid(); + this.payload = payload; + } + + public Object getId() { return this.id; }