Receives notifications from an observable stream of messages.
It is used for sending messages in bidi (bidirectional) or client-streaming calls, or for
receiving messages in bidi or server-streaming calls.
For outgoing messages, anApiStreamObserveris provided by GAX to the application, and
the application then provides the messages to send. For incoming messages, the application
implements theApiStreamObserverand passes it to GAX, which then calls the observer with
the messages for the application to receive them.
Implementations are expected to bethread-compatible. SeparateApiStreamObservers do not need to be synchronized together; incoming and outgoing
directions are independent. Since individualApiStreamObservers are not thread-safe, if
multiple threads will be writing to aApiStreamObserverconcurrently, the application
must synchronize calls.
This interface is a fork of io.grpc.stub.StreamObserver to enable shadowing of Guava, and also
to allow for a transport-agnostic interface that doesn't depend on gRPC.
Type Parameter
Name
Description
V
Methods
onCompleted()
publicabstractvoidonCompleted()
Receives a notification of successful stream completion.
May only be called once, and if called it must be the last method called. In particular if
an exception is thrown by an implementation ofonCompleted, no further calls to any
method are allowed.
onError(Throwable t)
publicabstractvoidonError(Throwablet)
Receives a terminating error from the stream.
May only be called once and if called, it must be the last method called. In particular if
an exception is thrown by an implementation ofonError, no further calls to any method
are allowed.
Clients may invoke onNext at most once for server streaming calls, but may receive many
onNext callbacks. Servers may invoke onNext at most once for client streaming calls, but may
receive many onNext callbacks.
If an exception is thrown by an implementation the caller is expected to terminate the
stream by calling#onError(Throwable)with the caught exception prior to propagating
it.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eApiStreamObserver\u003c/code\u003e interface receives notifications from an observable stream of messages, facilitating both sending and receiving in bidirectional or streaming calls.\u003c/p\u003e\n"],["\u003cp\u003eThis interface is a modified version of \u003ccode\u003eio.grpc.stub.StreamObserver\u003c/code\u003e, designed to be transport-agnostic and not dependent on gRPC, while also enabling shadowing of Guava.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eonCompleted()\u003c/code\u003e method signifies the successful end of a stream and must be the final method called, without subsequent method calls.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eonError(Throwable t)\u003c/code\u003e method is invoked when a stream terminates with an error, and must also be the final method called, without subsequent calls.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eonNext(V value)\u003c/code\u003e method is called to pass or receive values on the stream, but it will never be called if \u003ccode\u003eonCompleted()\u003c/code\u003e or \u003ccode\u003eonError(Throwable t)\u003c/code\u003e have already been invoked.\u003c/p\u003e\n"]]],[],null,["# Interface ApiStreamObserver<V> (2.69.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.69.0 (latest)](/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.68.2](/java/docs/reference/gax/2.68.2/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.67.0](/java/docs/reference/gax/2.67.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.66.0](/java/docs/reference/gax/2.66.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.65.0](/java/docs/reference/gax/2.65.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.63.1](/java/docs/reference/gax/2.63.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.62.0](/java/docs/reference/gax/2.62.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.61.0](/java/docs/reference/gax/2.61.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.60.0](/java/docs/reference/gax/2.60.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.59.1](/java/docs/reference/gax/2.59.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.58.0](/java/docs/reference/gax/2.58.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.57.0](/java/docs/reference/gax/2.57.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.55.0](/java/docs/reference/gax/2.55.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.54.1](/java/docs/reference/gax/2.54.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.53.0](/java/docs/reference/gax/2.53.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.52.0](/java/docs/reference/gax/2.52.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.51.0](/java/docs/reference/gax/2.51.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.50.0](/java/docs/reference/gax/2.50.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.49.0](/java/docs/reference/gax/2.49.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.48.1](/java/docs/reference/gax/2.48.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.47.0](/java/docs/reference/gax/2.47.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.46.1](/java/docs/reference/gax/2.46.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.45.0](/java/docs/reference/gax/2.45.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.43.0](/java/docs/reference/gax/2.43.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.42.0](/java/docs/reference/gax/2.42.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.41.0](/java/docs/reference/gax/2.41.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.39.0](/java/docs/reference/gax/2.39.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.38.0](/java/docs/reference/gax/2.38.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.37.0](/java/docs/reference/gax/2.37.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.36.0](/java/docs/reference/gax/2.36.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.35.0](/java/docs/reference/gax/2.35.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.34.1](/java/docs/reference/gax/2.34.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.33.0](/java/docs/reference/gax/2.33.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.32.1](/java/docs/reference/gax/2.32.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.31.1](/java/docs/reference/gax/2.31.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.30.1](/java/docs/reference/gax/2.30.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.24.0](/java/docs/reference/gax/2.24.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.23.3](/java/docs/reference/gax/2.23.3/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.22.0](/java/docs/reference/gax/2.22.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.21.0](/java/docs/reference/gax/2.21.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.20.1](/java/docs/reference/gax/2.20.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.19.6](/java/docs/reference/gax/2.19.6/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.18.7](/java/docs/reference/gax/2.18.7/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.17.0](/java/docs/reference/gax/2.17.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.16.0](/java/docs/reference/gax/2.16.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.15.0](/java/docs/reference/gax/2.15.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.14.0](/java/docs/reference/gax/2.14.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.13.0](/java/docs/reference/gax/2.13.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.12.2](/java/docs/reference/gax/2.12.2/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.11.0](/java/docs/reference/gax/2.11.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.10.0](/java/docs/reference/gax/2.10.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.9.0](/java/docs/reference/gax/2.9.0/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.8.1](/java/docs/reference/gax/2.8.1/com.google.api.gax.rpc.ApiStreamObserver)\n- [2.7.1](/java/docs/reference/gax/2.7.1/com.google.api.gax.rpc.ApiStreamObserver) \n\n public interface ApiStreamObserver\u003cV\u003e\n\nReceives notifications from an observable stream of messages.\n\nIt is used for sending messages in bidi (bidirectional) or client-streaming calls, or for\nreceiving messages in bidi or server-streaming calls.\n\nFor outgoing messages, an `ApiStreamObserver` is provided by GAX to the application, and\nthe application then provides the messages to send. For incoming messages, the application\nimplements the `ApiStreamObserver` and passes it to GAX, which then calls the observer with\nthe messages for the application to receive them.\n\nImplementations are expected to be [thread-compatible](http://www.ibm.com/developerworks/library/j-jtp09263/). Separate\n`ApiStreamObserver`s do not need to be synchronized together; incoming and outgoing\ndirections are independent. Since individual `ApiStreamObserver`s are not thread-safe, if\nmultiple threads will be writing to a `ApiStreamObserver` concurrently, the application\nmust synchronize calls.\n\nThis interface is a fork of io.grpc.stub.StreamObserver to enable shadowing of Guava, and also\nto allow for a transport-agnostic interface that doesn't depend on gRPC.\n\nMethods\n-------\n\n### onCompleted()\n\n public abstract void onCompleted()\n\nReceives a notification of successful stream completion.\n\nMay only be called once, and if called it must be the last method called. In particular if\nan exception is thrown by an implementation of `onCompleted`, no further calls to any\nmethod are allowed.\n\n### onError(Throwable t)\n\n public abstract void onError(Throwable t)\n\nReceives a terminating error from the stream.\n\nMay only be called once and if called, it must be the last method called. In particular if\nan exception is thrown by an implementation of `onError`, no further calls to any method\nare allowed.\n\n### onNext(V value)\n\n public abstract void onNext(V value)\n\nReceives a value from the stream.\n\nCan be called many times but is never called after [#onError(Throwable)](/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiStreamObserver#com_google_api_gax_rpc_ApiStreamObserver_onError_java_lang_Throwable_) or [#onCompleted()](/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiStreamObserver#com_google_api_gax_rpc_ApiStreamObserver_onCompleted__) are called.\n\nClients may invoke onNext at most once for server streaming calls, but may receive many\nonNext callbacks. Servers may invoke onNext at most once for client streaming calls, but may\nreceive many onNext callbacks.\n\nIf an exception is thrown by an implementation the caller is expected to terminate the\nstream by calling [#onError(Throwable)](/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiStreamObserver#com_google_api_gax_rpc_ApiStreamObserver_onError_java_lang_Throwable_) with the caught exception prior to propagating\nit."]]