Class Subscriber.Builder (1.133.0)

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
Type Description
FlowControlSettings

Methods

build()

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

Parameter
Name Description
channelProvider TransportChannelProvider
Returns
Type Description
Subscriber.Builder

setCredentialsProvider(CredentialsProvider credentialsProvider)

public Subscriber.Builder setCredentialsProvider(CredentialsProvider credentialsProvider)

CredentialsProvider to use to create Credentials to authenticate calls.

Parameter
Name Description
credentialsProvider CredentialsProvider
Returns
Type Description
Subscriber.Builder

setEnableOpenTelemetryTracing(boolean enableOpenTelemetryTracing)

public Subscriber.Builder setEnableOpenTelemetryTracing(boolean enableOpenTelemetryTracing)

Gives the ability to enable Open Telemetry Tracing

Parameter
Name Description
enableOpenTelemetryTracing boolean
Returns
Type Description
Subscriber.Builder

setEndpoint(String endpoint)

public Subscriber.Builder setEndpoint(String endpoint)

Gives the ability to override the gRPC endpoint.

Parameter
Name Description
endpoint String
Returns
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.

Parameter
Name Description
executorProvider ExecutorProvider
Returns
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();
 
Parameter
Name Description
flowControlSettings FlowControlSettings
Returns
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.

Parameter
Name Description
headerProvider HeaderProvider

the header provider

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

Parameter
Name Description
maxAckExtensionPeriod org.threeten.bp.Duration
Returns
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.

Parameter
Name Description
maxDurationPerAckExtension org.threeten.bp.Duration
Returns
Type Description
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
Name Description
minDurationPerAckExtension org.threeten.bp.Duration
Returns
Type Description
Subscriber.Builder

setOpenTelemetry(OpenTelemetry openTelemetry)

public Subscriber.Builder setOpenTelemetry(OpenTelemetry openTelemetry)

Sets the instance of OpenTelemetry for the Publisher class.

Parameter
Name Description
openTelemetry io.opentelemetry.api.OpenTelemetry
Returns
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.

Parameter
Name Description
parallelPullCount int
Returns
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.

Parameter
Name Description
executorProvider ExecutorProvider
Returns
Type Description
Subscriber.Builder

setUniverseDomain(String universeDomain)

public Subscriber.Builder setUniverseDomain(String universeDomain)

Gives the ability to override the universe domain.

Parameter
Name Description
universeDomain String
Returns
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.

Parameter
Name Description
value boolean
Returns
Type Description
Subscriber.Builder