Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save afsalthaj/e35a32433383850befa314e5f7ff749a to your computer and use it in GitHub Desktop.
Save afsalthaj/e35a32433383850befa314e5f7ff749a to your computer and use it in GitHub Desktop.
import scala.compat.java8.FutureConverters.toScala
// eh.send returns a completable future in Java. we convert it to Scala future
// and throttle sending the data to eventhub in azure nicely and easily!
private def sendDataInFutureControlled: Seq[EventData] => EventHubClient => Future[Iterator[Void]] =
seq => eh => {
// We throttle it and send in sequence to make sure that we are not overloading eventhub
Future.sequence(seq.grouped(3).map(s => toScala[Void](eh.send(s.asJava))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment