public static final class Subscriber.Builder
Builder of Subscribers.
Static Methods
getDefaultFlowControlSettings()
public static FlowControlSettings getDefaultFlowControlSettings()
Returns the default FlowControlSettings used by the client if settings are not provided.
Type | Description |
FlowControlSettings |
Methods
build()
public Subscriber build()
Type | Description |
Subscriber |
setChannelProvider(TransportChannelProvider channelProvider)
public Subscriber.Builder setChannelProvider(TransportChannelProvider channelProvider)
ChannelProvider
to use to create Channels, which must point at Cloud Pub/Sub
endpoint.
For performance, this client benefits from having multiple channels open at once. Users
are encouraged to provide instances of ChannelProvider
that creates new channels
instead of returning pre-initialized ones.
Name | Description |
channelProvider | TransportChannelProvider |
Type | Description |
Subscriber.Builder |
setCredentialsProvider(CredentialsProvider credentialsProvider)
public Subscriber.Builder setCredentialsProvider(CredentialsProvider credentialsProvider)
CredentialsProvider
to use to create Credentials to authenticate calls.
Name | Description |
credentialsProvider | CredentialsProvider |
Type | Description |
Subscriber.Builder |
setEndpoint(String endpoint)
public Subscriber.Builder setEndpoint(String endpoint)
Gives the ability to override the gRPC endpoint.
Name | Description |
endpoint | String |
Type | Description |
Subscriber.Builder |
setExecutorProvider(ExecutorProvider executorProvider)
public Subscriber.Builder setExecutorProvider(ExecutorProvider executorProvider)
Gives the ability to set a custom executor. ExecutorProvider#getExecutor() will be called Builder#parallelPullCount times.
Name | Description |
executorProvider | ExecutorProvider |
Type | Description |
Subscriber.Builder |
setFlowControlSettings(FlowControlSettings flowControlSettings)
public Subscriber.Builder setFlowControlSettings(FlowControlSettings flowControlSettings)
Sets the flow control settings.
In the example below, the Subscriber will make sure that
- there are at most ten thousand outstanding messages, and
- the combined size of outstanding messages does not exceed 1GB.
"Outstanding messages" here means the messages that have already been given to MessageReceiver but not yet acked()
or nacked()
.
FlowControlSettings flowControlSettings =
FlowControlSettings.newBuilder()
.setMaxOutstandingElementCount(10_000L)
.setMaxOutstandingRequestBytes(1_000_000_000L)
.build();
Subscriber subscriber =
Subscriber.newBuilder(subscriptionName, receiver)
.setFlowControlSettings(flowControlSettings)
.build();
Name | Description |
flowControlSettings | FlowControlSettings |
Type | Description |
Subscriber.Builder |
setHeaderProvider(HeaderProvider headerProvider)
public Subscriber.Builder setHeaderProvider(HeaderProvider headerProvider)
Sets the static header provider. The header provider will be called during client construction only once. The headers returned by the provider will be cached and supplied as is for each request issued by the constructed client. Some reserved headers can be overridden (e.g. Content-Type) or merged with the default value (e.g. User-Agent) by the underlying transport layer.
Name | Description |
headerProvider | HeaderProvider the header provider |
Type | Description |
Subscriber.Builder | the builder |
setMaxAckExtensionPeriod(Duration maxAckExtensionPeriod)
public Subscriber.Builder setMaxAckExtensionPeriod(Duration maxAckExtensionPeriod)
Set the maximum period a message ack deadline will be extended. Defaults to one hour.
It is recommended to set this value to a reasonable upper bound of the subscriber time to process any message. This maximum period avoids messages to be locked by a subscriber in cases when the ack reply is lost.
A zero duration effectively disables auto deadline extensions.
Name | Description |
maxAckExtensionPeriod | org.threeten.bp.Duration |
Type | Description |
Subscriber.Builder |
setMaxDurationPerAckExtension(Duration maxDurationPerAckExtension)
public Subscriber.Builder setMaxDurationPerAckExtension(Duration maxDurationPerAckExtension)
Set the upper bound for a single mod ack extention period.
The ack deadline will continue to be extended by up to this duration until MaxAckExtensionPeriod is reached. Setting MaxDurationPerAckExtension bounds the maximum amount of time before a mesage re-delivery in the event the Subscriber fails to extend the deadline.
MaxDurationPerAckExtension configuration can be disabled by specifying a zero duration.
Name | Description |
maxDurationPerAckExtension | org.threeten.bp.Duration |
Type | Description |
Subscriber.Builder |
setParallelPullCount(int parallelPullCount)
public Subscriber.Builder setParallelPullCount(int parallelPullCount)
Sets the number of StreamingPull streams to pull messages from the subscription. Defaults to one.
Name | Description |
parallelPullCount | int |
Type | Description |
Subscriber.Builder |
setSystemExecutorProvider(ExecutorProvider executorProvider)
public Subscriber.Builder setSystemExecutorProvider(ExecutorProvider executorProvider)
Gives the ability to set a custom executor for managing lease extensions. If none is provided a shared one will be used by all Subscriber instances.
Name | Description |
executorProvider | ExecutorProvider |
Type | Description |
Subscriber.Builder |
setUseLegacyFlowControl(boolean value)
public Subscriber.Builder setUseLegacyFlowControl(boolean value)
Disables enforcing flow control settings at the Cloud PubSub server and uses the less accurate method of only enforcing flow control at the client side.
Name | Description |
value | boolean |
Type | Description |
Subscriber.Builder |