Streaming does not work as expected. Retrofit + RxJava

@GET("poll/session/{sessionId}/details")
Observable getSessionDetails(@Path("sessionId") String sessionId);

@GET("poll/session/{sessionId}/details")
@Streaming
Observable getSessionDetails(@Path("sessionId") String sessionId);

@Override
public Observable getSessionDetails(String sessionId) {
return sessionAPI.getSessionDetails(sessionId)
.flatMap(responseBody -> events(responseBody.source()));
}

public static Observable<String> events(BufferedSource source) {
    return Observable.create(subscriber -> {
        try {
            while (!source.exhausted()) {
                subscriber.onNext(source.readUtf8Line());
            }
        } catch (IOException e) {
            e.printStackTrace();
            subscriber.onError(e);
        }
        subscriber.onCompleted();
    });
}

      

The events () method is not called if all chunks are not executed.

But chunk streams are expected to be delivered chunk by chunk, which doesn't seem to be happening.

I've tried with and without the @Streaming annotation to the API, but the behavior is the same.

I used Android Retrofit 2 + RxJava: listen to infinite stream as reference to my implementation

+3


source to share


1 answer


Ok guys, I found the answer. This happened because I was registering with the body attribute

logging.setLevel(HttpLoggingInterceptor.Level.BODY);

      



So, since the logger is waiting for the whole body to print it, it behaves as indicated in the problem.

link: Parsing the logic behind the Square relay response: streaming

+3


source







All Articles