Class Subscriber.Builder (1.123.18)

public static final class Subscriber.Builder

Builder of Subscribers.

Inheritance

java.lang.Object > Subscriber.Builder

Static Methods

getDefaultFlowControlSettings()

public static FlowControlSettings getDefaultFlowControlSettings()

Returns the default FlowControlSettings used by the client if settings are not provided.

Returns
TypeDescription
FlowControlSettings

Methods

build()

public Subscriber build()
Returns
TypeDescription
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.

Parameter
NameDescription
channelProviderTransportChannelProvider
Returns
TypeDescription
Subscriber.Builder

setCredentialsProvider(CredentialsProvider credentialsProvider)

public Subscriber.Builder setCredentialsProvider(CredentialsProvider credentialsProvider)

CredentialsProvider to use to create Credentials to authenticate calls.

Parameter
NameDescription
credentialsProviderCredentialsProvider
Returns
TypeDescription
Subscriber.Builder

setEndpoint(String endpoint)

public Subscriber.Builder setEndpoint(String endpoint)

Gives the ability to override the gRPC endpoint.

Parameter
NameDescription
endpointString
Returns
TypeDescription
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.

Parameter
NameDescription
executorProviderExecutorProvider
Returns
TypeDescription
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();
 
Parameter
NameDescription
flowControlSettingsFlowControlSettings
Returns
TypeDescription
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.

Parameter
NameDescription
headerProviderHeaderProvider

the header provider

Returns
TypeDescription
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.

Parameter
NameDescription
maxAckExtensionPeriodorg.threeten.bp.Duration
Returns
TypeDescription
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.

Parameter
NameDescription
maxDurationPerAckExtensionorg.threeten.bp.Duration
Returns
TypeDescription
Subscriber.Builder

setMinDurationPerAckExtension(Duration minDurationPerAckExtension)

public Subscriber.Builder setMinDurationPerAckExtension(Duration minDurationPerAckExtension)

Set the lower bound for a single mod ack extention period.

The ack deadline will continue to be extended by up to this duration until MinAckExtensionPeriod is reached. Setting MinDurationPerAckExtension bounds the minimum amount of time before a mesage re-delivery in the event the Subscriber fails to extend the deadline.

MinDurationPerAckExtension configuration can be disabled by specifying a zero duration.

Parameter
NameDescription
minDurationPerAckExtensionorg.threeten.bp.Duration
Returns
TypeDescription
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.

Parameter
NameDescription
parallelPullCountint
Returns
TypeDescription
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.

Parameter
NameDescription
executorProviderExecutorProvider
Returns
TypeDescription
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.

Parameter
NameDescription
valueboolean
Returns
TypeDescription
Subscriber.Builder