Package com.segment.analytics.messages
Class MessageBuilder<T extends Message,V extends MessageBuilder>
java.lang.Object
com.segment.analytics.messages.MessageBuilder<T,V>
- Direct Known Subclasses:
AliasMessage.Builder
,GroupMessage.Builder
,IdentifyMessage.Builder
,PageMessage.Builder
,ScreenMessage.Builder
,TrackMessage.Builder
public abstract class MessageBuilder<T extends Message,V extends MessageBuilder> extends Object
Fluent API to construct instances of a
Message
.
Note: Although it is not enforced by the compiler, either the Message.anonymousId()
or
Message.userId()
must be provided before calling build()
. Failure to do so will
result in a IllegalStateException
at runtime.
-
Method Summary
Modifier and Type Method Description V
anonymousId(String anonymousId)
The Anonymous ID is a pseudo-unique substitute for a User ID, for cases when you don’t have an absolutely unique identifier.V
anonymousId(UUID anonymousId)
Deprecated.T
build()
Create aMessage
instance.V
context(Map<String,?> context)
Set a map of information about the state of the device.V
enableIntegration(String key, boolean enable)
Set whether this message is sent to the specified integration or not.V
integrationOptions(String key, Map<String,?> options)
Pass in some options that will only be used by the target integration.V
messageId(String messageId)
The Message ID is a unique identifier for each message.V
messageId(UUID messageId)
Deprecated.UsemessageId(String)
instead.protected abstract T
realBuild(Message.Type type, String messageId, Date timestamp, Map<String,?> context, String anonymousId, String userId, Map<String,Object> integrations)
V
timestamp(Date timestamp)
Set a timestamp for the event.Message.Type
type()
Returns theMessage.Type
of the message this builder is constructing.V
userId(String userId)
The User ID is a persistent unique identifier for a user (such as a database ID).
-
Method Details
-
messageId
Deprecated.UsemessageId(String)
instead.The Message ID is a unique identifier for each message. If not provided, one will be generated for you. This ID is typically used for deduping - messages with the same IDs as previous events may be dropped.- See Also:
- Common Fields
-
messageId
The Message ID is a unique identifier for each message. If not provided, one will be generated for you. This ID is typically used for deduping - messages with the same IDs as previous events may be dropped.- See Also:
- Common Fields
-
timestamp
Set a timestamp for the event. By default, the current timestamp is used, but you may override it for historical import.- See Also:
- Timestamp
-
context
Set a map of information about the state of the device. You can add any custom data to the context dictionary that you'd like to have access to in the raw logs.Some keys in the context dictionary have semantic meaning and will be collected for you automatically, depending on the library you send data from. Some keys, such as location and speed need to be manually entered.
- See Also:
- Context
-
anonymousId
Deprecated.UseanonymousId(String)
instead.The Anonymous ID is a pseudo-unique substitute for a User ID, for cases when you don’t have an absolutely unique identifier.- See Also:
- Identities, Anonymous ID
-
anonymousId
The Anonymous ID is a pseudo-unique substitute for a User ID, for cases when you don’t have an absolutely unique identifier.- See Also:
- Identities, Anonymous ID
-
userId
The User ID is a persistent unique identifier for a user (such as a database ID).- See Also:
- Identities, User ID
-
enableIntegration
Set whether this message is sent to the specified integration or not. 'All' is a special key that applies when no key for a specific integration is found.- See Also:
- Integrations
-
integrationOptions
Pass in some options that will only be used by the target integration. This will implicitly mark the integration as enabled.- See Also:
- Integrations
-
realBuild
-
build
Create aMessage
instance.- Throws:
IllegalStateException
- if both anonymousId and userId are not provided.
-
type
Returns theMessage.Type
of the message this builder is constructing.
-
anonymousId(String)
instead.