public class Message extends Object implements Serializable
Message attributes are key-value pairs that a publisher can define for a message. For example,
a key iana.org/language_tag and value en could be added to messages to mark them
as readable by an English-speaking subscriber.
To be published, a message must have a non-empty payload, or at least one attribute.
| Modifier and Type | Class and Description |
|---|---|
static class |
Message.Builder
Builder for
Message objects. |
| Modifier and Type | Method and Description |
|---|---|
Map<String,String> |
attributes()
Returns the message attributes.
|
static Message.Builder |
builder(ByteArray payload)
Creates a builder for
Message objects given the payload as a ByteArray. |
static Message.Builder |
builder(String payload)
Creates a builder for
Message objects given the payload as a string. |
boolean |
equals(Object obj) |
int |
hashCode() |
String |
id()
Returns the id of this message, set by the server when the message is published.
|
static Message |
of(ByteArray payload)
Creates a
Message object given the payload as a ByteArray. |
static Message |
of(String payload)
Creates a
Message object given the payload as a string. |
ByteArray |
payload()
Returns the message payload.
|
String |
payloadAsString()
Returns the message payload as a string, decoded using
UTF-8. |
Long |
publishTime()
Returns the time in milliseconds at which the message was published.
|
Message.Builder |
toBuilder()
Returns a builder for the message object.
|
String |
toString() |
public Long publishTime()
null.public Map<String,String> attributes()
iana.org/language_tag and value en
could be added to messages to mark them as readable by an English-speaking subscriber.public String id()
null.public String payloadAsString()
UTF-8.public ByteArray payload()
public Message.Builder toBuilder()
public static Message of(String payload)
Message object given the payload as a string. The string is enconded using
UTF-8.public static Message of(ByteArray payload)
Message object given the payload as a ByteArray. To be published a
message must have a non-empty payload.public static Message.Builder builder(String payload)
Message objects given the payload as a string. The string is
enconded using UTF-8. To be published a message must have a non-empty payload.public static Message.Builder builder(ByteArray payload)
Message objects given the payload as a ByteArray. To be
published a message must have a non-empty payload, or at least one attribute.Copyright © 2016 Google. All rights reserved.