我有一个用例,我有一定数量的元素从源流入。这些元素得到处理,然后有一个Sink,在我们的例子中是一个ActorSubscriber。在发送所有元素之后,Source发出完整事件的信号。此事件将传播到接收器,接收器将触发onComplete事件并关闭流工作流。所有这些都发生在元素仍在中间步骤中处理时。
当中间步骤返回已处理数据时处理完成后,由于触发了onComplete事件,因此它已经关闭,因此找不到订阅者。有没有办法可以丢弃actor订阅者的onComplete事件并始终保持打开状态。
代码段:
val sample1 = //Sample time series
Source(List(sample1,sample2,sample3))
.map(m => akka.util.ByteString( m.getBytes ))
.to(detectionWorkflow(context))
.run()
val intakeBuffer = b.add(
Flow[ByteString]
.buffer(conf.tcpInboundBufferSize, OverflowStrategy.backpressure)
)
val timeSeries = b.add(
Flow[ByteString]
.via( watch("unpacking") )
.via( unmarshalTimeSeriesData )
.via( watch("unpacked") )
)
val scoring = b.add(
OutlierScoringModel.scoringGraph(planRouterRef = context.planRouter, config = conf)
)
intakeBuffer ~> timeSeries ~> scoring.in
scoring.out0 /*~> publishBuffer*/ ~> Sink.actorSubscriber(SpotlightSubscriber.props)
scoring.out1 ~> logUnrecognized ~> termUnrecognized
演员订阅者:
class SpotlightSubscriber extends ActorSubscriber with ActorLogging {
protected val logger: Logger = Logger(LoggerFactory.getLogger("SpotlightSubscriber"))
protected def requestStrategy = WatermarkRequestStrategy(1)
def receive = {
case OnNext(outlier: Outliers) =>
log.debug("[SpotlightSubscriber] Received : {}", outlier)
case OnError(err: Exception) =>
log.error(err, "[SpotlightSubscriber] Received Exception in Spotlight Stream")
context.stop(self)
case OnComplete =>
log.info("[SpotlightSubscriber] Spotlight Stream Completed!")
context.stop(self)
case _ => }}
评分是否有效。发生的事情是有3个元素将完整事件发送到接收器的源。一旦从源接收到完整事件,就会触发actorSubscriber的onComplete事件。处理后,评分引擎将处理后的结果发送回actorSubscriber,但由于它不再处于活动状态,我们会收到deadLetter消息。