ribbon: Issues with blocking observable

Hi,

Having issues getting the blocking requests working. In order to support backwards compatibility in our clients we support returning both Observable<T> and T. To get the Observable we do:

    Observable<ByteBuf> observable = template.requestBuilder().build().observe();
    Observable<T> response = observable.map(new Func1<ByteBuf, T>() {
                @Override
                public T call(ByteBuf byteBuf) {
                    byteBuf.retain();
                     try {
                        InputStream stream = new ByteBufInputStream(byteBuf);
                        return streamToObject(stream, tClass);
                    } finally {
                        byteBuf.release();
                    }
              }});
    T item = response.toBlocking().last();

That works well for MOST of the times. However, sometimes we get: java.util.NoSuchElementException: Sequence contains no elements.

Anyone have any idea?

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Comments: 19

Most upvoted comments

@NiteshKant at least I am not seeing that specific error any more. I also tried doing the same for futures with something like this; observable.lastOrDefault().toBlocking().toFuture();

Does that sound right?

At what point will the default value be invoked? How can we be sure that the only case this happens if a response has been indeed been returned but the bytebuf was empty? Having huge issues trying to make this backwards compatible. Seems like we’re getting false defaults…