I am currently building a solution to stream data from mongoDb to elasticsearch. My goal is to keep track of all successful transmitted items to elasticsearch. I am using akka-streams and elastic4s. Currently the streaming into es looks like this
val esSubscriber: BulkIndexingSubscriber[CustomT] = esClient.subscriber[CustomT](
batchSize = batchSize,
completionFn = { () => elasticFinishPromise.success(()); ()},
errorFn = { (t: Throwable) => elasticFinishPromise.failure(t); ()},
concurrentRequests = concurrentRequests
)
val esSink: Sink[CustomT, NotUsed] = Sink.fromSubscriber(esSubscriber)
And from my source something like this:
val a: [NotUsed] = mongoSrc
.via(some operations..)
.to(esSink)
.run()
Now everything works fine and right now I am logging for example item count with a second sink. But I would rather log the items really transmitted to elasticsearch.
The elastic4s subscriber offers a listener: ResponseListener
with onAck(): Unit
and onFailure(): Unit
and I would love to get this information back into the stream like this
val mongoSrc: [Source..]
val doStuff: [Flow..]
val esSink: [Flow..] //now as flow instead of sink
val logSink: [Sink[Int...]] //now gets for example a 1 for each successful transported item
mongoSrc ~> doStuff ~> esSink ~> logSink
How would I implement that? Do I need a custom stage which buffers the elements of the onAck
and the onFailure
? Or is there an easier way?
Thanks for any help.