Class DefaultSubscriberFactory
java.lang.Object
com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory
- All Implemented Interfaces:
SubscriberFactory
The default
SubscriberFactory
implementation.-
Constructor Summary
ConstructorDescriptionDefaultSubscriberFactory
(GcpProjectIdProvider projectIdProvider, PubSubConfiguration pubSubConfiguration) DefaultDefaultSubscriberFactory
constructor. -
Method Summary
Modifier and TypeMethodDescriptioncom.google.pubsub.v1.PullRequest
createPullRequest
(String subscriptionName, Integer maxMessages, Boolean returnImmediately) Create aPullRequest
for synchronously pulling a number of messages from a Google Cloud Pub/Sub subscription.com.google.cloud.pubsub.v1.Subscriber
createSubscriber
(String subscriptionName, com.google.cloud.pubsub.v1.MessageReceiver receiver) Create aSubscriber
for the specified subscription name and wired it up to asynchronously deliver messages to the providedMessageReceiver
.com.google.cloud.pubsub.v1.stub.SubscriberStub
createSubscriberStub
(String subscriptionName) Create aSubscriberStub
that is needed to executePullRequest
s.com.google.api.gax.core.ExecutorProvider
getExecutorProvider
(String subscriptionName) CreatesExecutorProvider
.com.google.api.gax.batching.FlowControlSettings
getFlowControlSettings
(String subscriptionName) Fetches subscriberFlowControlSettings
.com.google.api.gax.core.ExecutorProvider
Method to get the project id.com.google.api.gax.rpc.StatusCode.Code[]
getRetryableCodes
(String subscriptionName) com.google.api.gax.retrying.RetrySettings
getRetrySettings
(String subscriptionName) CreatesRetrySettings
, given subscriber retry properties.void
setApiClock
(com.google.api.core.ApiClock apiClock) Set the clock to use for the retry logic in synchronous pulling.void
setChannelProvider
(com.google.api.gax.rpc.TransportChannelProvider channelProvider) Set the provider for the subscribers' transport channel.void
setCredentialsProvider
(com.google.api.gax.core.CredentialsProvider credentialsProvider) Set the provider for the GCP credentials to be used by the subscribers' API calls.void
setExecutorProvider
(com.google.api.gax.core.ExecutorProvider executorProvider) Set the provider for the subscribers' executor.void
setExecutorProviderMap
(Map<com.google.pubsub.v1.ProjectSubscriptionName, com.google.api.gax.core.ExecutorProvider> executorProviderMap) void
setFlowControlSettings
(com.google.api.gax.batching.FlowControlSettings flowControlSettings) Set the flow control for the subscribers, including the behaviour for when the flow limits are hit.void
setFlowControlSettingsMap
(Map<com.google.pubsub.v1.ProjectSubscriptionName, com.google.api.gax.batching.FlowControlSettings> flowControlSettingsMap) void
setGlobalExecutorProvider
(com.google.api.gax.core.ExecutorProvider executorProvider) void
setGlobalFlowControlSettings
(com.google.api.gax.batching.FlowControlSettings flowControlSettings) void
setGlobalRetrySettings
(com.google.api.gax.retrying.RetrySettings retrySettings) void
setHeaderProvider
(com.google.api.gax.rpc.HeaderProvider headerProvider) Set the provider for the HTTP headers to be added to the subscribers' REST API calls.void
setHealthTrackerRegistry
(HealthTrackerRegistry healthTrackerRegistry) Set the health tracker chain for the generated subscriptions.void
setMaxAckExtensionPeriod
(org.threeten.bp.Duration maxAckExtensionPeriod) Set the maximum period the ack timeout is extended by.void
setMaxDurationPerAckExtension
(org.threeten.bp.Duration maxDurationPerAckExtension) Sets the max duration per ack extension override for all subscriptions.void
setMinDurationPerAckExtension
(org.threeten.bp.Duration minDurationPerAckExtension) Sets the min duration per ack extension override for all subscriptions.void
setParallelPullCount
(Integer parallelPullCount) Set the number of pull workers.void
setPullEndpoint
(String pullEndpoint) Set the endpoint for pulling messages.void
setRetryableCodes
(com.google.api.gax.rpc.StatusCode.Code[] retryableCodes) Set the retryable codes for subscriber pull settings.void
setRetrySettingsMap
(Map<com.google.pubsub.v1.ProjectSubscriptionName, com.google.api.gax.retrying.RetrySettings> retrySettingsMap) void
setSubscriberStubRetrySettings
(com.google.api.gax.retrying.RetrySettings subscriberStubRetrySettings) Set the retry settings for the generated subscriber stubs.void
setSystemExecutorProvider
(com.google.api.gax.core.ExecutorProvider systemExecutorProvider) Set the provider for the system executor, to poll and manage lease extensions.
-
Constructor Details
-
DefaultSubscriberFactory
public DefaultSubscriberFactory(GcpProjectIdProvider projectIdProvider, PubSubConfiguration pubSubConfiguration) DefaultDefaultSubscriberFactory
constructor.- Parameters:
projectIdProvider
- provides the default GCP project ID for selecting the subscriptionspubSubConfiguration
- contains the subscriber properties to configure
-
-
Method Details
-
getProjectId
Description copied from interface:SubscriberFactory
Method to get the project id.- Specified by:
getProjectId
in interfaceSubscriberFactory
- Returns:
- the project id
-
setExecutorProvider
public void setExecutorProvider(com.google.api.gax.core.ExecutorProvider executorProvider) Set the provider for the subscribers' executor. Useful to specify the number of threads to be used by each executor.- Parameters:
executorProvider
- the executor provider to set
-
setChannelProvider
public void setChannelProvider(com.google.api.gax.rpc.TransportChannelProvider channelProvider) Set the provider for the subscribers' transport channel.- Parameters:
channelProvider
- the channel provider to set
-
setCredentialsProvider
public void setCredentialsProvider(com.google.api.gax.core.CredentialsProvider credentialsProvider) Set the provider for the GCP credentials to be used by the subscribers' API calls.- Parameters:
credentialsProvider
- the credentials provider to set
-
setHeaderProvider
public void setHeaderProvider(com.google.api.gax.rpc.HeaderProvider headerProvider) Set the provider for the HTTP headers to be added to the subscribers' REST API calls.- Parameters:
headerProvider
- the header provider to set
-
setSystemExecutorProvider
public void setSystemExecutorProvider(com.google.api.gax.core.ExecutorProvider systemExecutorProvider) Set the provider for the system executor, to poll and manage lease extensions.- Parameters:
systemExecutorProvider
- the system executor provider to set
-
setFlowControlSettings
public void setFlowControlSettings(com.google.api.gax.batching.FlowControlSettings flowControlSettings) Set the flow control for the subscribers, including the behaviour for when the flow limits are hit.- Parameters:
flowControlSettings
- the flow control settings to set
-
setMaxAckExtensionPeriod
public void setMaxAckExtensionPeriod(org.threeten.bp.Duration maxAckExtensionPeriod) Set the maximum period the ack timeout is extended by.- Parameters:
maxAckExtensionPeriod
- the max ack extension period to set
-
setParallelPullCount
Set the number of pull workers.- Parameters:
parallelPullCount
- the parallel pull count to set
-
setPullEndpoint
Set the endpoint for pulling messages.- Parameters:
pullEndpoint
- the pull endpoint to set
-
setApiClock
public void setApiClock(com.google.api.core.ApiClock apiClock) Set the clock to use for the retry logic in synchronous pulling.- Parameters:
apiClock
- the api clock to set
-
setSubscriberStubRetrySettings
public void setSubscriberStubRetrySettings(com.google.api.gax.retrying.RetrySettings subscriberStubRetrySettings) Set the retry settings for the generated subscriber stubs.- Parameters:
subscriberStubRetrySettings
- parameters for retrying pull requests when they fail, including jitter logic, timeout, and exponential backoff
-
setRetryableCodes
public void setRetryableCodes(com.google.api.gax.rpc.StatusCode.Code[] retryableCodes) Set the retryable codes for subscriber pull settings.- Parameters:
retryableCodes
- pull RPC response codes that should be retried.
-
setHealthTrackerRegistry
Set the health tracker chain for the generated subscriptions.- Parameters:
healthTrackerRegistry
- parameter for registering health trackers when creating subscriptions
-
createSubscriber
public com.google.cloud.pubsub.v1.Subscriber createSubscriber(String subscriptionName, com.google.cloud.pubsub.v1.MessageReceiver receiver) Description copied from interface:SubscriberFactory
Create aSubscriber
for the specified subscription name and wired it up to asynchronously deliver messages to the providedMessageReceiver
.- Specified by:
createSubscriber
in interfaceSubscriberFactory
- Parameters:
subscriptionName
- the name of the subscriptionreceiver
- the callback for receiving messages asynchronously- Returns:
- the
Subscriber
that was created to bind the receiver to the subscription
-
createPullRequest
public com.google.pubsub.v1.PullRequest createPullRequest(String subscriptionName, Integer maxMessages, Boolean returnImmediately) Description copied from interface:SubscriberFactory
Create aPullRequest
for synchronously pulling a number of messages from a Google Cloud Pub/Sub subscription.- Specified by:
createPullRequest
in interfaceSubscriberFactory
- Parameters:
subscriptionName
- the name of the subscriptionmaxMessages
- the maximum number of pulled messages; must be greater than zero. If null is passed in, then up to Integer.MAX_VALUE messages will be requested.returnImmediately
- causes the pull request to return immediately even if subscription doesn't contain enough messages to satisfymaxMessages
. Setting this parameter totrue
is not recommended as it may result in long delays in message delivery.- Returns:
- the pull request that can be executed using a
SubscriberStub
-
createSubscriberStub
Description copied from interface:SubscriberFactory
Create aSubscriberStub
that is needed to executePullRequest
s.- Specified by:
createSubscriberStub
in interfaceSubscriberFactory
- Parameters:
subscriptionName
- the subscription name- Returns:
- the
SubscriberStub
used for executingPullRequest
s
-
getExecutorProvider
CreatesExecutorProvider
. If a custom executor provider is set then the subscriber properties configured through the application.properties file will be ignored.- Parameters:
subscriptionName
- subscription name- Returns:
- executor provider
-
getRetrySettings
CreatesRetrySettings
, given subscriber retry properties. Returns null if none of the retry settings are set. Note that if retry settings are set using a Spring-managed bean then subscription-specific settings in application.properties are ignored.- Parameters:
subscriptionName
- subscription name- Returns:
- retry settings for subscriber
-
getFlowControlSettings
public com.google.api.gax.batching.FlowControlSettings getFlowControlSettings(String subscriptionName) Fetches subscriberFlowControlSettings
. User-provided bean takes precedence over properties from application.properties. Returns subscription-specific flow control settings if present, otherwise, returns global subscriber settings.- Parameters:
subscriptionName
- subscription name- Returns:
- flow control settings for subscriber
-
setMinDurationPerAckExtension
public void setMinDurationPerAckExtension(@Nullable org.threeten.bp.Duration minDurationPerAckExtension) Sets the min duration per ack extension override for all subscriptions.- Parameters:
minDurationPerAckExtension
- the min duration per ack extension
-
setMaxDurationPerAckExtension
public void setMaxDurationPerAckExtension(@Nullable org.threeten.bp.Duration maxDurationPerAckExtension) Sets the max duration per ack extension override for all subscriptions.- Parameters:
maxDurationPerAckExtension
- the max duration per ack extension
-
getRetryableCodes
-
setExecutorProviderMap
public void setExecutorProviderMap(Map<com.google.pubsub.v1.ProjectSubscriptionName, com.google.api.gax.core.ExecutorProvider> executorProviderMap) -
setGlobalExecutorProvider
public void setGlobalExecutorProvider(com.google.api.gax.core.ExecutorProvider executorProvider) -
getGlobalExecutorProvider
public com.google.api.gax.core.ExecutorProvider getGlobalExecutorProvider() -
setFlowControlSettingsMap
public void setFlowControlSettingsMap(Map<com.google.pubsub.v1.ProjectSubscriptionName, com.google.api.gax.batching.FlowControlSettings> flowControlSettingsMap) -
setGlobalFlowControlSettings
public void setGlobalFlowControlSettings(com.google.api.gax.batching.FlowControlSettings flowControlSettings) -
setRetrySettingsMap
public void setRetrySettingsMap(Map<com.google.pubsub.v1.ProjectSubscriptionName, com.google.api.gax.retrying.RetrySettings> retrySettingsMap) -
setGlobalRetrySettings
public void setGlobalRetrySettings(com.google.api.gax.retrying.RetrySettings retrySettings)
-