Package org.apache.pulsar.common.topics
Interface TopicCompactionStrategy<T>
Defines a custom strategy to compact messages in a topic.
This strategy can be passed to Topic Compactor and Table View to compact messages in a custom way.
Examples:
TopicCompactionStrategy strategy = new MyTopicCompactionStrategy();
// Run topic compaction by the compaction strategy.
// While compacting messages for each key,
// it will choose messages only if TopicCompactionStrategy.shouldKeepLeft(prev, cur) returns false.
StrategicTwoPhaseCompactor compactor = new StrategicTwoPhaseCompactor(...);
compactor.compact(topic, strategy);
// Run table view by the compaction strategy.
// While updating messages in the table view <key,value> map,
// it will choose messages only if TopicCompactionStrategy.shouldKeepLeft(prev, cur) returns false.
TableView tableView = pulsar.getClient().newTableViewBuilder(strategy.getSchema())
.topic(topic)
.loadConf(Map.of(
"topicCompactionStrategyClassName", strategy.getClass().getCanonicalName()))
.create();
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Map<String,
TopicCompactionStrategy> static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic TopicCompactionStrategy
getInstance
(String tag) Returns the schema object for this strategy.default void
handleSkippedMessage
(String key, T cur) static TopicCompactionStrategy
boolean
shouldKeepLeft
(T prev, T cur) Tests if the compaction needs to keep the left(previous message) compared to the right(current message) for the same key.
-
Field Details
-
TABLE_VIEW_TAG
- See Also:
-
INSTANCES
-
-
Method Details
-
getSchema
Returns the schema object for this strategy.- Returns:
-
shouldKeepLeft
Tests if the compaction needs to keep the left(previous message) compared to the right(current message) for the same key.- Parameters:
prev
- previous message valuecur
- current message value- Returns:
- True if it needs to keep the previous message and ignore the current message. Otherwise, False.
-
handleSkippedMessage
-
load
-
getInstance
-