接口 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();
-
字段概要
字段 -
方法概要
修饰符和类型方法说明static TopicCompactionStrategygetInstance(String tag) Returns the schema object for this strategy.default voidhandleSkippedMessage(String key, T cur) static TopicCompactionStrategybooleanshouldKeepLeft(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.
-
字段详细资料
-
TABLE_VIEW_TAG
- 另请参阅:
-
INSTANCES
-
-
方法详细资料
-
getSchema
Returns the schema object for this strategy.- 返回:
-
shouldKeepLeft
Tests if the compaction needs to keep the left(previous message) compared to the right(current message) for the same key.- 参数:
prev- previous message valuecur- current message value- 返回:
- True if it needs to keep the previous message and ignore the current message. Otherwise, False.
-
handleSkippedMessage
-
load
-
getInstance
-