Home » Tag Archives: RxJava

Tag Archives: RxJava

flatMap() and the order of events – RxJava FAQ

As we already discovered, flatMap() does not preserve the order of original stream. Let’s illustrate this using the GeoNames API example from previous article: public interface GeoNames { Flowable<Long> populationOf(String city); } By requesting population of multiple cities using flatMap() we have no guarantee that they will arrive in order: Flowable<String> cities = Flowable.just("Warsaw", "Paris", "London", "Madrid"); cities .flatMap(geoNames::populationOf) .subscribe(response -> log.info("Population: {}", response)); The output is ...

Read More »

flatMap() vs. concatMap() vs. concatMapEager() – RxJava FAQ

java-interview-questions-answers

There are three, seamlessly similar operators in RxJava 2.x: flatMap(), concatMap() and concatMapEager(). All of them accept the same argument – a function from original stream’s individual item to a (sub-)stream of arbitrary type. In other words if you have a Flowable<T> you provide a function from T to Flowable<R> for arbitrary R type. After applying any of these operators you end up with Flowable<R>. So how are they different? Sample project First ...

Read More »

Eager subscription – RxJava FAQ

java-interview-questions-answers

While teaching and mentoring RxJava, as well as after authoring a book, I noticed some areas are especially problematic. I decided to publish a bunch of short tips that address most common pitfalls. This is the first part. Observables and Flowables are lazy by nature. This means no matter how heavy or long-running logic you place inside your Flowable, it will get evaluated ...

Read More »

Small scale stream processing kata. Part 2: RxJava 1.x/2.x

In part 1: thread pools we designed and implemented relatively simple system for processing events in real time. Make sure you read previous part as it contains some classes that we’ll reuse. Just in case here are the requirements: A system delivers around one thousand events per second. Each Event has at least two attributes: clientId – we expect up ...

Read More »

Parallel execution of blocking tasks with RxJava and Completable

” How parallel execution of blocking “side-effect only” (aka void) tasks became easier with Completable abstraction introduced in RxJava 1.1.1. “ As you may have noticed reading my blog I primarily specialize in Software Craftsmanship and automatic code testing. However, in addition I am an enthusiast of Continuous Delivery and broadly defined concurrency. The last point ranges from pure threads ...

Read More »

Server-sent events with RxJava and SseEmitter

java-interview-questions-answers

Spring framework 4.2 GA is almost released, let’s look at some new features it provides. The one that got my attention is a simple new class SseEmitter – an abstraction over sever-sent events easily used in Spring MVC controllers. SSE is a technology that allows you to stream data from server to the browser within one HTTP connection in one ...

Read More »

Use reactive streams API to combine akka-streams with rxJava

Just a quick article this time, since I’m still experimenting with this stuff. There is a lot of talk around reactive programming. In Java 8 we’ve got the Stream API, we got rxJava we got ratpack and Akka has got akka-streams. The main issue with these implementations is that they aren’t compatible. You can’t connect the subscriber of one implementation ...

Read More »

RxJava + Java8 + Java EE 7 + Arquillian = Bliss

Microservices are an architectural style where each service is implemented as an independent system. They can use their own persistence system (although it is not mandatory), deployment, language, … Because a system is composed by more than one service, each service will communicate with other services, typically using a lightweight protocol like HTTP and following a Restful Web approach. You ...

Read More »

Turning Twitter4J into RxJava’s Observable

aTwitter4J is a Java wrapper around Twitter API. While Twitter supports simple request-response interactions in this article we will explore streaming APIs. In contrary to request-response model which is always initiated by the client, streaming API pushes data from Twitter server to the clients as soon as they are available. Of course in case of Twitter we are talking about ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns