Class DefaultSubscriberFactory

java.lang.Object
com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory
All Implemented Interfaces:
SubscriberFactory

public class DefaultSubscriberFactory extends Object implements SubscriberFactory
The default SubscriberFactory implementation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultSubscriberFactory(GcpProjectIdProvider projectIdProvider, PubSubConfiguration pubSubConfiguration)
    Default DefaultSubscriberFactory constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.pubsub.v1.PullRequest
    createPullRequest(String subscriptionName, Integer maxMessages, Boolean returnImmediately)
    Create a PullRequest 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 a Subscriber for the specified subscription name and wired it up to asynchronously deliver messages to the provided MessageReceiver.
    com.google.cloud.pubsub.v1.stub.SubscriberStub
    createSubscriberStub(String subscriptionName)
    Create a SubscriberStub that is needed to execute PullRequests.
    com.google.api.gax.core.ExecutorProvider
    getExecutorProvider(String subscriptionName)
    Creates ExecutorProvider.
    com.google.api.gax.batching.FlowControlSettings
    getFlowControlSettings(String subscriptionName)
    Fetches subscriber FlowControlSettings.
    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)
    Creates RetrySettings, 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
    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
    setParallelPullCount(Integer parallelPullCount)
    Set the number of pull workers.
    void
    setPullEndpoint(String pullEndpoint)
    Set the endpoint for synchronous 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultSubscriberFactory

      public DefaultSubscriberFactory(GcpProjectIdProvider projectIdProvider, PubSubConfiguration pubSubConfiguration)
      Default DefaultSubscriberFactory constructor.
      Parameters:
      projectIdProvider - provides the default GCP project ID for selecting the subscriptions
      pubSubConfiguration - contains the subscriber properties to configure
  • Method Details

    • getProjectId

      public String getProjectId()
      Description copied from interface: SubscriberFactory
      Method to get the project id.
      Specified by:
      getProjectId in interface SubscriberFactory
      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

      public void setParallelPullCount(Integer parallelPullCount)
      Set the number of pull workers.
      Parameters:
      parallelPullCount - the parallel pull count to set
    • setPullEndpoint

      public void setPullEndpoint(String pullEndpoint)
      Set the endpoint for synchronous 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

      public void setHealthTrackerRegistry(HealthTrackerRegistry healthTrackerRegistry)
      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 a Subscriber for the specified subscription name and wired it up to asynchronously deliver messages to the provided MessageReceiver.
      Specified by:
      createSubscriber in interface SubscriberFactory
      Parameters:
      subscriptionName - the name of the subscription
      receiver - 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 a PullRequest for synchronously pulling a number of messages from a Google Cloud Pub/Sub subscription.
      Specified by:
      createPullRequest in interface SubscriberFactory
      Parameters:
      subscriptionName - the name of the subscription
      maxMessages - 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 satisfy maxMessages. Setting this parameter to true 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

      public com.google.cloud.pubsub.v1.stub.SubscriberStub createSubscriberStub(String subscriptionName)
      Description copied from interface: SubscriberFactory
      Create a SubscriberStub that is needed to execute PullRequests.
      Specified by:
      createSubscriberStub in interface SubscriberFactory
      Parameters:
      subscriptionName - the subscription name
      Returns:
      the SubscriberStub used for executing PullRequests
    • getExecutorProvider

      public com.google.api.gax.core.ExecutorProvider getExecutorProvider(String subscriptionName)
      Creates ExecutorProvider. 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

      public com.google.api.gax.retrying.RetrySettings getRetrySettings(String subscriptionName)
      Creates RetrySettings, 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 subscriber FlowControlSettings. 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
    • getRetryableCodes

      public com.google.api.gax.rpc.StatusCode.Code[] getRetryableCodes(String subscriptionName)
    • 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)