【发布时间】:2017-03-29 16:10:39
【问题描述】:
我希望从事件流中投射出一个可能非常大的状态。这就是我可能以一种命令式的方式实现它的方式:
class ImperativeFooProcessor {
val state: mutable.Map[UUID, BarState] = mutable.HashMap.empty[UUID, BarState]
def handle(event: InputEvent) = {
event match {
case FooAdded(fooId, barId) => {
// retrieve relevant state and do some work on it
val barState = state(barId)
// let the world know about what may have happened
publish(BarOccured(fooId, barId))
// or maybe rather
publish(BazOccured(fooId, barId))
}
case FooRemoved(fooId, barId) => {
// retrieve relevant state and do some work on it
val barState = state(barId)
// let the world know about what may have happened
publish(BarOccured(fooId, barId))
// or maybe rather
publish(BazOccured(fooId, barId))
}
}
}
private def publish(event: OutputEvent): Unit = {
// push event to downstream sink
}
}
在最坏的情况下,BarState 的大小会随着 FooAdded 提及的次数而增长
相对于每个 barId 的事件总数而言,唯一 barId 的数量非常少。
我将如何开始在 Flink 中表示这种处理结构?
如何处理每个 BarState 都可能变得非常大的事实?
【问题讨论】:
标签: scala apache-flink flink-streaming