Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Christian Vivas Santiago
    @christian130
    but is already running in the ui thread
    this
    .observeOn(AndroidSchedulers.mainThread());
    it's executing the subscriber in the main
    Christian Vivas Santiago
    @christian130
    I figured out to use Rx and also the ProgressBar across with the textView using an iteration technique with the manual create "Observable"... in this https://github.com/christian130/ReactProgramming/tree/lesson03
    Mark Alvaro
    @markaalvaro
    Looking at the RxJava 3 javadocs and see the packages have changed for all of the classes. Is that going to be the case for the final release? I was confused about how the binary compatibility is supposed to work. Sorry if this has been asked--was struggling to find it.
    Mark Alvaro
    @markaalvaro
    Also I did find this thread, but not sure where it landed: ReactiveX/RxJava#5622
    David Karnok
    @akarnokd
    @markaalvaro Yes, the new package organization will stay. You'll have to change imports for RxJava 3 and recompile your project. You can have RxJava 2 and 3 in the same project if needed, but bridge is needed so convert between the various versions of the components. The changes of #5622 have been applied. Here is a full list of changes: ReactiveX/RxJava#6515 . Also check out the changelog in each RC release: https://github.com/ReactiveX/RxJava/releases
    Mark Alvaro
    @markaalvaro
    Awesome! Thanks for the info!
    matrixbot
    @matrixbot
    Andreas Does anyone know if there is work underway for AndroidX LiveData and AndroidX Room to support RxJava 3? I assume due to the packaging and API changes the existing RxJava 2 support doesn't work any more.
    David Karnok
    @akarnokd
    They were most likely waiting for the full release before adding support.
    matrixbot
    @matrixbot
    Andreas That's understandable, but did anyone (Google or else) state they will work on this?
    Andreas I'm asking because maybe they are into Kotlin and Flow/Coroutines so much that they don't care about RxJava any more.
    yulibanpenagos
    @yulibanpenagos
    Hello all. I'm just trying rx java and I'm facing issues when my flows run in different threads other than main. The flow is pretty simple: I'm receiving an event from kafka, with info from that event I call an external service and with the results I update a record in a DB like this (this is not the real version but it's the idea):
    Flowable.just(message)
            .map(mapToSomeObject)
            .map(
                event -> {
                  callSomeExternalService(event);
                })
            .subscribeOn(Schedulers.io())
            .doOnNext(
                results ->
                    results.forEach(
                        result -> {
                          log.info("Doing things");
                          dao.update(result);
                        }))
            .doOnError(
                error ->
                // just logging
                    log.error(
                        "There was an error."));
                        )
            .subscribe(
                x -> log.info("onNext {}", x),
                error -> {
                  log.error("There was an error in the stream {}", error.getMessage());
                },
                () -> log.info("onComplete"))
            .dispose()
    If I remove .subscribeOn(Schedulers.io()) it works, otherwise, it seems like it is doing nothing. Any help is appreciated.
    Dan O'Reilly
    @dano
    @yulibanpenagos why are you disposing the subscription immediately after creating it?
    that might be the cause of the problem, actually
    disposing it will cancel the emissions from upstream. When you run them in the main thread, the subscribe call blocks, so everything completes before dispose is called, but when you subscribe in background thread, subscribe doesn't block, so the subscription is cancelled immediately after creation
    yulibanpenagos
    @yulibanpenagos
    @dano thanks for your response and yes, you are right! Now I wonder how should I dispose the stream then? Should I move back to the main thread and then dipose?
    Dan O'Reilly
    @dano
    if the flow completes normally, you don't need to dispose it at all - you only need to dispose it if you need to interrupt the flow for some reason - e.g. you don't need it any more and don't want to wait for it to finish/delay releasing resources it's using
    it's a common concern for people using RxJava on Android, because Activities/Views that rx flows execute in can get stopped while they're still running
    yulibanpenagos
    @yulibanpenagos
    I see, thank you!
    rezo
    @shalika08_twitter
    Hello.
    I don't know if it's okay to post stack overflow questions here but. can you take a look at my question?
    I'm trying to make state update in scan function sequential. Meaning that multiple concurrent events should wait in quite until previous state update is complete. One answer suggested using Schedulers.single() but I want to make it work without scheduler.
    yulibanpenagos
    @yulibanpenagos

    Hello all. I'd like to know how can I keep a Flowable emitting items and processing them after an exception occurs. Per my understanding, there are some handlers that may help with it but I tried them all and they are not working. This is very briefly what I'm doing:

    Flowable.fromIterable(input)
    .map(flowable -> codeThrowingError())
    .onErrorResumeNext(err -> Flowable.empty())
    .subscribe()

    However, after the exception is thrown, the pending items in the flowable are not processed. The flow just stop doing things. Is it a way to make this work? TIA.

    Dan O'Reilly
    @dano
    @yulibanpenagos You have to catch the error and swallow it before it escapes to the "top-level" of your rx chain. Like this, for example:
    Flowable.fromIterable(input)
        .flatMap(ign -> Flowable.fromCallable(() -> codeThrowingError())
            .onErrorResumeNext(err -> Flowable.empty())
        )
        .subscribe()
    yulibanpenagos
    @yulibanpenagos
    @dano it worked! thanks. It spawns another question tho. Do I need to add that kind of code to every place I'm doing something to the observer? I mean say I have this:
    Flowable.fromIterable(input)
        .flatMap(ign -> Flowable.fromCallable(() -> codeThrowingError())
            .onErrorResumeNext(err -> Flowable.empty())
        )
        . map(x -> moreCodeThatMayThrowAnException()) // here I'd need to add the code to catch the exc again?
        .subscribe()
    I'd need to catch the error again right?
    Dan O'Reilly
    @dano
    @yulibanpenagos yep! If I have a Flowable/Observable that I want to ensure doesn't get terminated early due to downstream errors, I embed all the downstream operators inside of a flatMap, and then swallow all errors at the end of the embedded chain
    yulibanpenagos
    @yulibanpenagos
    OK thanks!
    Dan O'Reilly
    @dano
    just to clarify, i mean do this:
    Flowable.fromIterable(input)
        .flatMap(ign -> Flowable.fromCallable(() -> codeThrowingError())
            .map(x -> moreCodeThatMayThrowAnException())
            .onErrorResumeNext(err -> Flowable.empty())
        )
        .subscribe()
    yulibanpenagos
    @yulibanpenagos
    Oh, got it!
    slisaasquatch
    @slisaasquatch

    I'm looking for a way of gzipping a Publisher<ByteBuffer> (or Publisher<byte[]> or anything equivalent).

    So far I've found that Akka Streams actually has this functionality built-in. These are the helper methods I have right now:

        public static Flowable<ByteBuffer> gzip(Publisher<ByteBuffer> bytesPublisher,
                int level, Materializer mat) {
            final Publisher<akka.util.ByteString> resultPublisher =
                    Source.fromPublisher(bytesPublisher)
                    .map(akka.util.ByteString::fromByteBuffer)
                    .via(akka.stream.javadsl.Compression.gzip(level))
                    .runWith(Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), mat);
            return Flowable.fromPublisher(resultPublisher)
                    .map(akka.util.ByteString::toByteBuffer);
        }
    
        public static Flowable<ByteBuffer> gunzip(Publisher<ByteBuffer> bytesPublisher,
                int maxBytesPerChunk, Materializer mat) {
            final Publisher<akka.util.ByteString> resultPublisher =
                    Source.fromPublisher(bytesPublisher)
                    .map(akka.util.ByteString::fromByteBuffer)
                    .via(akka.stream.javadsl.Compression.gunzip(maxBytesPerChunk))
                    .runWith(Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), mat);
            return Flowable.fromPublisher(resultPublisher)
                    .map(akka.util.ByteString::toByteBuffer);
        }

    These are less than elegant because they require a Materializer, which I don't normally use.

    So does anyone know of another library that can achieve this in a more elegant way (without the need for something like a Materializer)?

    Thanks!

    yulibanpenagos
    @yulibanpenagos

    Hello all!. So I want to parallelise an observable and I tried a couple of thins. First:

    Flowable.fromIterable(loadSomeValuesFroms3())
    .flatMap(value -> Flowable.just(callExternalService(value)
                                       .subscribeOn(Shedulers.io()) // This is expensive so I want run this in parallel.
    )
    .map(response -> mapToDomainObject(response))
    .map(domainObject -> doSomeDomainThing(domainObject))
    .map(domainObject -> mapToDTO(domainObject))
    .doOnNext(dto -> saveToDB(dto))
    .subscribe()

    And

    Flowable.fromIterable(loadSomeValuesFroms3())
    .parallel(10)
    .map(value -> callExternalService(value)) // This is expensive so I want to run this in parallel.
    .map(response -> mapToDomainObject(response))
    .map(domainObject -> doSomeDomainThing(domainObject))
    .map(domainObject -> mapToDTO(domainObject))
    .runOn(Schedullers.io())
    .sequential()
    .doOnNext(dto -> saveToDB(dto))
    .subscribe()

    I'm reading a csv file that contains 10000 items. But it doesn't seem to be processing that quantity, when I check the db there are about 200 registers. I added an atomic counter as well and the ouput: firstly changes with every new run and secondly is similar to what I have in the DB. I've added counters to errors and it is not consistent trhough runs and it's not even near to the 10000 register I'm expecting to be processed.

    In the second version if I put a bigger value in .parallel(10) say to 10000 it seems to be processing more registers. I don't see errors with back off or something related to it so I'm kind of lost. I Hope you guys can help me. TIA.
    yulibanpenagos
    @yulibanpenagos
    • back off -> bakcpressure
    Rodrigo Prandi
    @rodrigoprandi_twitter
    Hi guys
    I need help to resolve this issue:
    I need to ensure that the logService.setProcessing (monitorTransactionLogId) .subscribe () method is completed before the logService.setSuccess (monitorTransactionLogId) .subscribe () or logService.setError (monitorTransactionLogId, throwable) .subscribe () method
    Rodrigo Prandi
    @rodrigoprandi_twitter
    getBigDataPropertiesMessage(textMessage)
                    .doFirst(() ->  logService.setProcessing(monitorTransactionLogId).subscribe())
                    .flatMap(bigDataMessageDto -> bigDataSender.callBigDataSender(bigDataMessageDto.getMessage(), bigDataMessageDto.getPartitionKey(), bigDataMessageDto.getBigDataEnum()))
                    .doOnSuccess(response -> {
                        //do something
                        logService.setSuccess(monitorTransactionLogId).subscribe();
                    })
                    .doOnError(throwable -> {
                        logService.setError(monitorTransactionLogId, throwable).subscribe();
                    })
                    .subscribe();
    Boris Petrov
    @boris-petrov
    I'm not sure I completely understand something... is it possible a subscribe method on an Observable to be called in parallel (that is, a call to not wait for the previous one to finish)? If so, could someone give me some simple example code that would cause that?
    I mean subscribe's onNext callback of course.
    yelhouti
    @yelhouti
    Hi. can anyone help me with this?

    I'm using Spring reactive as a server to make an expensive generation and return the results in Flux one by one. This has the advantage of stopping the generation if the request is cancelled (in cas the constraints and are too tight for example). My code look like this:

        public Flux<Entity> generate(int nbrOfEntitiesToGenerate, Constaints constraints) {
            return Flux.range(0, nbrOfEntitiesToGenerate)
                .map(x -> Generator.expensiveGeneration(constraints)
    //            .subscribeOn(Schedulers.parallel())
                ;
        }

    This only does half of what I want, I doesn't make the next call expensiveGeneration when cancelled, but doesn't stop currently running expensive generation that might never finish if the constraints are too tight. How can I do that please.

    Extra question if you know, how can I generate x entities in parralel to maximize the use of my threads, (of course without starting ALL the generations at once).

    Thanks in advance.

    yelhouti
    @yelhouti
    if any one ansewers, please ping me
    slisaasquatch
    @slisaasquatch
    @yelhouti From your code sample, expensiveGeneration is a blocking method, so I don't think there's a way of cancelling it in the land of RxJava or Reactor Core.
    For executing in parallel, since your method is blocking, you'll probably have to do something like this
    Flux.range(0, 10)
    .parallel(4)
    .runOn(scheduler)
    .map(x -> expensiveGeneration())
    .sequential();
    If expensiveGeneration is not blocking, i.e. it returns a Publisher, then you can do this:
    Flux.range(0, 10)
    .flatMap(x -> expensiveGeneration(), 4);
    Andrey
    @404-

    in the process of evaluating RxJava, i've run into strange behavior while attempting recursion. first, i noticed that RxJava is not stacksafe (please correct me if i'm wrong). second, while attempting to get around the stackoverflow issues, i've gotten into a situation where a very simple program seemingly hangs. here's the bit of code (in Kotlin) i'm working with:

    package demos
    
    import io.reactivex.rxjava3.core.Flowable
    import io.reactivex.rxjava3.core.Single
    import io.reactivex.rxjava3.schedulers.Schedulers
    import java.util.concurrent.TimeUnit.SECONDS
    
    fun main() {
        fun incr(n: Int): Single<Int> = Single.just(n + 1)
    
        fun numbers(n: Int, max: Int): Flowable<Int> = Flowable.just(n).concatWith(
            if (n < max)
                incr(n).observeOn(Schedulers.single()).toFlowable().concatMap { next -> numbers(next, max) }
            else
                Flowable.empty()
        )
    
        numbers(1, 1_000_000).sample(5, SECONDS).blockingForEach(::println)
    }

    without the call to .observeOn(Schedulers.single()), the stack explodes... with it, the first few sampled numbers get printed and then... just... nothing, e.g.:

    14737
    19765
    23398
    23802

    would really appreciate any help/advice.

    Aman Bansal
    @aman210697
    java.lang.NoSuchMethodError: No static method trampoline()
    Getting this error in android unit testing