@Generated(value="by gapic-generator-java") public class PublisherServiceClient extends Object implements com.google.api.gax.core.BackgroundResource
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 for illustrative purposes only.
// It may require modifications to work in your environment.
try (PublisherServiceClient publisherServiceClient = PublisherServiceClient.create()) {
BidiStream<PublishRequest, PublishResponse> bidiStream =
publisherServiceClient.publishCallable().call();
PublishRequest request = PublishRequest.newBuilder().build();
bidiStream.send(request);
for (PublishResponse response : bidiStream) {
// Do something when a response is received.
}
}
Note: close() needs to be called on the PublisherServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
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 PublisherServiceSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
PublisherServiceSettings publisherServiceSettings =
PublisherServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
PublisherServiceClient publisherServiceClient =
PublisherServiceClient.create(publisherServiceSettings);
To customize the endpoint:
// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
PublisherServiceSettings publisherServiceSettings =
PublisherServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
PublisherServiceClient publisherServiceClient =
PublisherServiceClient.create(publisherServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
| Modifier | Constructor and Description |
|---|---|
protected |
PublisherServiceClient(PublisherServiceSettings settings)
Constructs an instance of PublisherServiceClient, using the given settings.
|
protected |
PublisherServiceClient(PublisherServiceStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static PublisherServiceClient |
create()
Constructs an instance of PublisherServiceClient with default settings.
|
static PublisherServiceClient |
create(PublisherServiceSettings settings)
Constructs an instance of PublisherServiceClient, using the given settings.
|
static PublisherServiceClient |
create(PublisherServiceStub stub)
Constructs an instance of PublisherServiceClient, using the given stub for making calls.
|
PublisherServiceSettings |
getSettings() |
PublisherServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
com.google.api.gax.rpc.BidiStreamingCallable<PublishRequest,PublishResponse> |
publishCallable()
Establishes a stream with the server for publishing messages.
|
void |
shutdown() |
void |
shutdownNow() |
protected PublisherServiceClient(PublisherServiceSettings settings) throws IOException
IOExceptionprotected PublisherServiceClient(PublisherServiceStub stub)
public static final PublisherServiceClient create() throws IOException
IOExceptionpublic static final PublisherServiceClient create(PublisherServiceSettings settings) throws IOException
IOExceptionpublic static final PublisherServiceClient create(PublisherServiceStub stub)
public final PublisherServiceSettings getSettings()
public PublisherServiceStub getStub()
public final com.google.api.gax.rpc.BidiStreamingCallable<PublishRequest,PublishResponse> publishCallable()
Sample code:
// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
try (PublisherServiceClient publisherServiceClient = PublisherServiceClient.create()) {
BidiStream<PublishRequest, PublishResponse> bidiStream =
publisherServiceClient.publishCallable().call();
PublishRequest request = PublishRequest.newBuilder().build();
bidiStream.send(request);
for (PublishResponse response : bidiStream) {
// Do something when a response is received.
}
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2022 Google LLC. All rights reserved.