Read CommandCompletionStream response and stop

I got two questions here.

  1. In what condition onComplete() will be called?
       Disposable t = res.subscribeWith(new DisposableSubscriber<CompletionStreamResponse>(){
            @Override
            public void onNext(CompletionStreamResponse completionStreamResponse) {
                completionStreamResponse.getCompletions()
                        .forEach(completion -> {
                           //do something here. 
                        });
            }
            @Override
            public void onError(Throwable throwable) {
                // do something here               
            }

            @Override
            public void onComplete() {                

            }
        });
  1. If a caller starts to stream the completions from an offset, the completion stream will be hanging there waiting after all the results been streamed out. Is there any way to find out it has reached the end of the ledger and stop it?
1 Like

Regarding your first question, onComplete is called when a stream emits its last element. The completion stream however never ends, so you should never see that being called.

Regarding the second, it’s a bit tricky, because there is a CompletionEnd service but that returns the offset to which you are supposed to subscribe to, I don’t think you could use it to detect when you reached the ledger end.

The completion service is not designed to access historical data, but to keep up with an ongoing stream of commands. What is it exactly that you need? Unless you are explicitly looking for failures that happened in the past, you are more likely to get useful information using the transaction service, which can be queried for historical data by giving two explicit offsets.

4 Likes

Thanks for the answer. I was just exploring those services and see what we can get from them. Also looking into the impact that pruning potential can bring into those services.

1 Like