Service Description: The service that a subscriber client application uses to receive messages
from subscriptions.
This class provides the ability to make remote calls to the backing service through method
calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_librarytry(SubscriberServiceClientsubscriberServiceClient=SubscriberServiceClient.create()){BidiStream<SubscribeRequest,SubscribeResponse>bidiStream=subscriberServiceClient.subscribeCallable().call();SubscribeRequestrequest=SubscribeRequest.newBuilder().build();bidiStream.send(request);for(SubscribeResponseresponse:bidiStream){// Do something when a response is received.}}
Note: close() needs to be called on the SubscriberServiceClient object to clean up resources
such as threads. In the example above, try-with-resources is used, which automatically calls
close().
Methods
Method
Description
Method Variants
Subscribe
Establishes a stream with the server for receiving messages.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
subscribeCallable()
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with
these names, this class includes a format method for each type of name, and additionally a parse
method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of SubscriberServiceSettings to
create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_librarySubscriberServiceSettingssubscriberServiceSettings=SubscriberServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)).build();SubscriberServiceClientsubscriberServiceClient=SubscriberServiceClient.create(subscriberServiceSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_librarySubscriberServiceSettingssubscriberServiceSettings=SubscriberServiceSettings.newBuilder().setEndpoint(myEndpoint).build();SubscriberServiceClientsubscriberServiceClient=SubscriberServiceClient.create(subscriberServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Constructs an instance of SubscriberServiceClient, using the given settings. The channels are
created based on the settings passed in, or defaults for any settings that are not set.
Constructs an instance of SubscriberServiceClient, using the given stub for making calls. This
is for advanced usage - prefer using create(SubscriberServiceSettings).
Constructs an instance of SubscriberServiceClient, using the given settings. This is protected
so that it is easy to make a subclass, but otherwise, the static factory methods should be
preferred.
Establishes a stream with the server for receiving messages.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_librarytry(SubscriberServiceClientsubscriberServiceClient=SubscriberServiceClient.create()){BidiStream<SubscribeRequest,SubscribeResponse>bidiStream=subscriberServiceClient.subscribeCallable().call();SubscribeRequestrequest=SubscribeRequest.newBuilder().build();bidiStream.send(request);for(SubscribeResponseresponse:bidiStream){// Do something when a response is received.}}
[[["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-08-28 UTC."],[],[],null,["# Class SubscriberServiceClient (1.15.13)\n\nVersion latestkeyboard_arrow_down\n\n- [1.15.13 (latest)](/java/docs/reference/google-cloud-pubsublite/latest/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.15.12](/java/docs/reference/google-cloud-pubsublite/1.15.12/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.14.8](/java/docs/reference/google-cloud-pubsublite/1.14.8/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.13.8](/java/docs/reference/google-cloud-pubsublite/1.13.8/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.12.22](/java/docs/reference/google-cloud-pubsublite/1.12.22/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.11.2](/java/docs/reference/google-cloud-pubsublite/1.11.2/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.10.0](/java/docs/reference/google-cloud-pubsublite/1.10.0/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.9.4](/java/docs/reference/google-cloud-pubsublite/1.9.4/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.8.0](/java/docs/reference/google-cloud-pubsublite/1.8.0/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.7.1](/java/docs/reference/google-cloud-pubsublite/1.7.1/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.6.3](/java/docs/reference/google-cloud-pubsublite/1.6.3/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.5.5](/java/docs/reference/google-cloud-pubsublite/1.5.5/com.google.cloud.pubsublite.v1.SubscriberServiceClient)\n- [1.4.12](/java/docs/reference/google-cloud-pubsublite/1.4.12/com.google.cloud.pubsublite.v1.SubscriberServiceClient) \n\nService Description: The service that a subscriber client application uses to receive messages\nfrom subscriptions.\n\nThis class provides the ability to make remote calls to the backing service through method\ncalls that map to API methods. Sample code to get started: \n\n\n // This snippet has been automatically generated and should be regarded as a code template only.\n // It will require modifications to work:\n // - It may require correct/in-range values for request initialization.\n // - It may require specifying regional endpoints when creating the service client as shown in\n // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library\n try (SubscriberServiceClient subscriberServiceClient = SubscriberServiceClient.create()) {\n BidiStream\u003cSubscribeRequest, SubscribeResponse\u003e bidiStream =\n subscriberServiceClient.subscribeCallable().call();\n SubscribeRequest request = SubscribeRequest.newBuilder().build();\n bidiStream.send(request);\n for (SubscribeResponse response : bidiStream) {\n // Do something when a response is received.\n }\n }\n \nNote: close() needs to be called on the SubscriberServiceClient object to clean up resources\nsuch as threads. In the example above, try-with-resources is used, which automatically calls\nclose().\n\nSee the individual methods for example code.\n\nMany parameters require resource names to be formatted in a particular way. To assist with\nthese names, this class includes a format method for each type of name, and additionally a parse\nmethod to extract the individual identifiers contained within names that are returned.\n\nThis class can be customized by passing in a custom instance of SubscriberServiceSettings to\ncreate(). For example:\n\nTo customize credentials: \n\n\n // This snippet has been automatically generated and should be regarded as a code template only.\n // It will require modifications to work:\n // - It may require correct/in-range values for request initialization.\n // - It may require specifying regional endpoints when creating the service client as shown in\n // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library\n SubscriberServiceSettings subscriberServiceSettings =\n SubscriberServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))\n .build();\n SubscriberServiceClient subscriberServiceClient =\n SubscriberServiceClient.create(subscriberServiceSettings);\n \nTo customize the endpoint: \n\n\n // This snippet has been automatically generated and should be regarded as a code template only.\n // It will require modifications to work:\n // - It may require correct/in-range values for request initialization.\n // - It may require specifying regional endpoints when creating the service client as shown in\n // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library\n SubscriberServiceSettings subscriberServiceSettings =\n SubscriberServiceSettings.newBuilder().setEndpoint(myEndpoint).build();\n SubscriberServiceClient subscriberServiceClient =\n SubscriberServiceClient.create(subscriberServiceSettings);\n \nPlease refer to the GitHub repository's samples for more quickstart code snippets. \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e SubscriberServiceClient\n\nStatic Methods\n--------------\n\n### create()\n\n public static final SubscriberServiceClient create()\n\nConstructs an instance of SubscriberServiceClient with default settings.\n\n### create(SubscriberServiceSettings settings)\n\n public static final SubscriberServiceClient create(SubscriberServiceSettings settings)\n\nConstructs an instance of SubscriberServiceClient, using the given settings. The channels are\ncreated based on the settings passed in, or defaults for any settings that are not set.\n\n### create(SubscriberServiceStub stub)\n\n public static final SubscriberServiceClient create(SubscriberServiceStub stub)\n\nConstructs an instance of SubscriberServiceClient, using the given stub for making calls. This\nis for advanced usage - prefer using create(SubscriberServiceSettings).\n\nConstructors\n------------\n\n### SubscriberServiceClient(SubscriberServiceSettings settings)\n\n protected SubscriberServiceClient(SubscriberServiceSettings settings)\n\nConstructs an instance of SubscriberServiceClient, using the given settings. This is protected\nso that it is easy to make a subclass, but otherwise, the static factory methods should be\npreferred.\n\n### SubscriberServiceClient(SubscriberServiceStub stub)\n\n protected SubscriberServiceClient(SubscriberServiceStub stub)\n\nMethods\n-------\n\n### awaitTermination(long duration, TimeUnit unit)\n\n public boolean awaitTermination(long duration, TimeUnit unit)\n\n### close()\n\n public final void close()\n\n### getSettings()\n\n public final SubscriberServiceSettings getSettings()\n\n### getStub()\n\n public SubscriberServiceStub getStub()\n\n### isShutdown()\n\n public boolean isShutdown()\n\n### isTerminated()\n\n public boolean isTerminated()\n\n### shutdown()\n\n public void shutdown()\n\n### shutdownNow()\n\n public void shutdownNow()\n\n### subscribeCallable()\n\n public final BidiStreamingCallable\u003cSubscribeRequest,SubscribeResponse\u003e subscribeCallable()\n\nEstablishes a stream with the server for receiving messages.\n\nSample code: \n\n\n // This snippet has been automatically generated and should be regarded as a code template only.\n // It will require modifications to work:\n // - It may require correct/in-range values for request initialization.\n // - It may require specifying regional endpoints when creating the service client as shown in\n // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library\n try (SubscriberServiceClient subscriberServiceClient = SubscriberServiceClient.create()) {\n BidiStream\u003cSubscribeRequest, SubscribeResponse\u003e bidiStream =\n subscriberServiceClient.subscribeCallable().call();\n SubscribeRequest request = SubscribeRequest.newBuilder().build();\n bidiStream.send(request);\n for (SubscribeResponse response : bidiStream) {\n // Do something when a response is received.\n }\n }"]]