我已经定义了以下rxjava(Kotlin)代码来创建无阻塞,背压敏感的生成器。生成器通过Jackson JSON Api JsonParser从Azure Blob存储提供了JSON的非阻塞流,该流提供了非常专业和快速的解析。我的downloadBlob()方法返回一个Single<ByteBuffer>
,我将生成器附加到该Single<Flowable<Sample>>
上。我无法弄清楚为什么将生成器变量报告为Flowable<Sample>
而不是Flowable<Sample>
。非常感谢您提出的提取 /**
* Method generator parses sample data from a json stream.
* @param sampleJsonUrl String is the URL to the Azure Blob Storage sample data.
* @return Flowable<Sample>> is a cold, synchronous, stateful and backpressure-aware
* generator of features.
*/
fun generator(sampleJsonUrl: String) =
blobStorage.downloadBlob(sampleJsonUrl)
.map { bbuf: ByteBuffer -> JsonFactory().createParser(bbuf.array()) }
.map { jParser ->
Flowable.generate<Sample, JsonParser>(
java.util.concurrent.Callable { jParser.gobbleJsonToSamples() },
io.reactivex.functions.BiConsumer<JsonParser, Emitter<Sample>> {
parser: JsonParser, emitter: Emitter<Sample> ->
pullOrComplete(parser, emitter)
},
Consumer<JsonParser> { jParser.close() }
)
}.flatMapPublisher { it }
/**
* Method downloadBlob will retrieve a blob from storage and return a
* reactive stream of bytes.
* @param url String is the url to the blob.
* @return Single<ByteBuffer> is the blob's content.
*/
override fun downloadBlob(url: String): Single<ByteBuffer> =
BlockBlobURL(URL(url), pipeline)
.download(null, null, false, null)
.flatMap {
FlowableUtil
.collectBytesInBuffer(
it.body(ReliableDownloadOptions().withMaxRetryRequests(3))
)
}
的建议,这是我所需要的。我在这个问题上碰壁...:(
感谢您的帮助和时间。
$group