public final class Message<Payload> extends Object
This provides access to both the message payload, and the metadata.
Modifier and Type | Method and Description |
---|---|
<Metadata> Message<Payload> |
add(MetadataKey<Metadata> key,
Metadata metadata)
Add a metadata key and value to this message.
|
static <Payload> Message<Payload> |
create(Payload payload)
Create a message with the given payload.
|
<Metadata> Optional<Metadata> |
get(MetadataKey<Metadata> key)
Get the metadata for the given metadata key.
|
Payload |
getPayload()
The payload of the message.
|
String |
messageKeyAsString()
Get the message key as a String.
|
<P2> Message<P2> |
withPayload(P2 payload)
Return a copy of this message with the given payload.
|
public Payload getPayload()
public <Metadata> Optional<Metadata> get(MetadataKey<Metadata> key)
key
- The key of the metadata.public <Metadata> Message<Payload> add(MetadataKey<Metadata> key, Metadata metadata)
key
- The key to add.metadata
- The metadata to add.public <P2> Message<P2> withPayload(P2 payload)
payload
- The payload.public String messageKeyAsString()
If the key is not a String, it will be converted to a String using toString
.
If the underlying message broker doesn't support keys, the empty string will be returned.
public static <Payload> Message<Payload> create(Payload payload)