|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2016 the original author or authors. |
| 2 | + * Copyright 2014-2018 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 |
|
21 | 21 | import org.springframework.data.annotation.AccessType;
|
22 | 22 | import org.springframework.data.annotation.Id;
|
| 23 | +import org.springframework.data.annotation.PersistenceConstructor; |
23 | 24 | import org.springframework.data.mongodb.core.mapping.Document;
|
24 | 25 | import org.springframework.messaging.Message;
|
25 | 26 | import org.springframework.util.Assert;
|
@@ -63,11 +64,24 @@ public class MessageDocument {
|
63 | 64 | private int sequence;
|
64 | 65 |
|
65 | 66 | public MessageDocument(Message<?> message) {
|
| 67 | + this(message, message.getHeaders().getId()); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * The special persistence constructor to populate a {@code final} |
| 72 | + * properties from the source MongoDB document. |
| 73 | + * @param message the {@link Message} this document is assigned. |
| 74 | + * @param messageId the id of the {@link Message} as a separate persistent property. |
| 75 | + * @since 5.1 |
| 76 | + */ |
| 77 | + @PersistenceConstructor |
| 78 | + MessageDocument(Message<?> message, UUID messageId) { |
66 | 79 | Assert.notNull(message, "'message' must not be null");
|
67 | 80 | this.message = message;
|
68 |
| - this.messageId = message.getHeaders().getId(); |
| 81 | + this.messageId = messageId; |
69 | 82 | }
|
70 | 83 |
|
| 84 | + |
71 | 85 | public Message<?> getMessage() {
|
72 | 86 | return this.message;
|
73 | 87 | }
|
|
0 commit comments