Azure Blob Storage Java SDK: Why isn't asynchronous working?

岁酱吖の 提交于 2019-12-13 03:49:57

问题


I am still spinning up on the Azure Storage Java SDK 10 and its use of reactive programming the paradigm. I wrote the following method to asynchronously download a blob to a byte stream as fast as possible. When I use the synchronous version (below), it works properly. When I comment out the blockingAwait() and uncomment the subscribe, the write and the doOnComplete never are executed... Basically, the run just falls out of the bottom of the method back to the caller. I am sure that I have made an asynchronous processing mistake, and hope that someone can steer me in the correct direction. By the way, I was surprised to find that there are very few samples of downloading to a stream rather than to a file... Hopefully, this posting will help others.

Thank you for your time and interest in my problem...

override fun downloadBlob(url: String, downloadStream: OutputStream) {

    BlockBlobURL(URL(url), pipeline)
            .download(null, null, false, null)
            .flatMapCompletable { response ->
                FlowableUtil.collectBytesInBuffer(response.body(null))
                        .map {
                            Channels.newChannel(downloadStream).write(it)
                        }.toCompletable()
            }.doOnComplete {
                println("The blob was downloaded...")
            }.blockingAwait()
            //.subscribe()
}

Here is the code that is calling the above method:

fun getAerialImageBlobStream(aerialImageUrl: String): MapOutputStream {

    val aerialImageStream = MapOutputStream()
    blobStorage.downloadBlob(aerialImageUrl, aerialImageStream)
    return aerialImageStream
}

来源:https://stackoverflow.com/questions/55605560/azure-blob-storage-java-sdk-why-isnt-asynchronous-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!