public final class AggregateEventTag<Event extends AggregateEvent<Event>> extends Object implements AggregateEventTagger<Event>
PersistentEntity
events may return one of these
to make the events available for read-side processing.
The tag
should be unique among the event types of the service.
The class name can be used as tag
, but note that it is needed
to retain the original tag when the class name is changed because
the tag is part of the store event data.
Constructor and Description |
---|
AggregateEventTag(Class<Event> eventType,
String tag) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
Class<Event> |
eventType() |
int |
hashCode() |
static <Event extends AggregateEvent<Event>> |
of(Class<Event> eventType)
Convenience factory method of
AggregateEventTag that uses the
class name of the event type as tag . |
static <Event extends AggregateEvent<Event>> |
of(Class<Event> eventType,
String tag)
Factory method of
AggregateEventTag . |
static int |
selectShard(int numShards,
String entityId)
Select a shard given the number of shards and the ID of the entity.
|
static <Event extends AggregateEvent<Event>> |
sharded(Class<Event> eventType,
int numShards)
Create an aggregate event shards tagger.
|
static <Event extends AggregateEvent<Event>> |
sharded(Class<Event> eventType,
String baseTagName,
int numShards)
Create a sharded aggregate event tag.
|
static String |
shardTag(String baseTagName,
int shardNo)
Generate a shard tag according to the base tag name and the shard number.
|
String |
tag() |
String |
toString() |
public static <Event extends AggregateEvent<Event>> AggregateEventTag<Event> of(Class<Event> eventType)
AggregateEventTag
that uses the
class name of the event type as tag
. Note that it is needed to
retain the original tag when the class name is changed because
the tag is part of the store event data.public static <Event extends AggregateEvent<Event>> AggregateEventTag<Event> of(Class<Event> eventType, String tag)
AggregateEventTag
.public static <Event extends AggregateEvent<Event>> AggregateEventShards<Event> sharded(Class<Event> eventType, int numShards)
This is a convenience function that uses the name of the class as the tag name. Note that if the class name changes, the tag name must be retained, and so this method will no longer be suitable for use.
Events that return this will be tagged with a tag that is based on a hash of the events persistence ID, modulo the number of shards.
The numShards
should be selected up front, and shouldn't change. If it does change, events for the
same entity will be produced by different event streams and handled by different shards in the read side
processor, leading to out of order event handling.
eventType
- The type of the event.numShards
- The number of shards.public static <Event extends AggregateEvent<Event>> AggregateEventShards<Event> sharded(Class<Event> eventType, String baseTagName, int numShards)
Events that return this will be tagged with a tag that is based on a hash of the events persistence ID, modulo the number of shards.
The numShards
should be selected up front, and shouldn't change. If it does change, events for the
same entity will be produced by different event streams and handled by different shards in the read side
processor, leading to out of order event handling.
eventType
- The type of the event.baseTagName
- The base name for the tag, this will be combined with the shard number to form the tag name.numShards
- The number of shards.public static int selectShard(int numShards, String entityId)
numShards
- The number of shards.entityId
- The ID of the entity.public static String shardTag(String baseTagName, int shardNo)
baseTagName
- The base tag name.shardNo
- The shard number.public Class<Event> eventType()
eventType
in interface AggregateEventTagger<Event extends AggregateEvent<Event>>
public String tag()