Class PubSubMessageHandler

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
com.google.cloud.spring.pubsub.integration.outbound.PubSubMessageHandler
All Implemented Interfaces:
org.reactivestreams.Subscriber<org.springframework.messaging.Message<?>>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.core.Ordered, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.Orderable, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.TrackableComponent, org.springframework.messaging.MessageHandler, reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>

public class PubSubMessageHandler extends org.springframework.integration.handler.AbstractMessageHandler
Outbound channel adapter to publish messages to Google Cloud Pub/Sub.

It delegates Google Cloud Pub/Sub interaction to PubSubTemplate.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Implement this callback to post-process a message that failed to publish to Cloud Pub/Sub.
    static interface 
    Implement this callback to post-process a successfully published message.

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • Field Summary

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
    PubSubMessageHandler(PubSubPublisherOperations pubSubPublisherOperations, String topic)
    Instantiates an outbound adapter for publishing messages to a topic.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    org.springframework.expression.Expression
     
    org.springframework.expression.Expression
     
    protected void
    handleMessageInternal(org.springframework.messaging.Message<?> message)
     
    boolean
     
    protected void
     
    void
    Set callback (can be a lambda) for processing the root cause exception and the original Message in case of failure.
    void
    setHeaderMapper(org.springframework.integration.mapping.HeaderMapper<Map<String,String>> headerMapper)
    Set the header mapper to map headers from Message into outbound PubsubMessage.
    void
    setPublishTimeout(long timeoutMillis)
    Set the timeout in milliseconds for a synchronous publish call to Google Cloud Pub/Sub.
    void
    setPublishTimeoutExpression(org.springframework.expression.Expression publishTimeoutExpression)
    Set the SpEL expression to evaluate a timeout in milliseconds for a synchronous publish call to Google Cloud Pub/Sub.
    void
    setPublishTimeoutExpressionString(String publishTimeoutExpression)
    Set the SpEL expression to evaluate a timeout in milliseconds for a synchronous publish call to Google Cloud Pub/Sub from a string.
    void
    Set callback (can be a lambda) for processing the published message ID and the original Message after the message was successfully published.
    void
    setSync(boolean sync)
    Set publish method to be synchronous or asynchronous.
    void
    Set the topic where this adapter sends messages to.
    void
    setTopicExpression(org.springframework.expression.Expression topicExpression)
    Set the SpEL expression for the topic this adapter sends messages to.
    void
    setTopicExpressionString(String topicExpressionString)
    Set the topic expression string that is evaluated into an actual expression.

    Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler

    handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention

    Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport

    buildSendTimer, destroy, getComponentType, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack

    Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport

    afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface reactor.core.CoreSubscriber

    currentContext

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    getThisAs

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName
  • Constructor Details

    • PubSubMessageHandler

      public PubSubMessageHandler(PubSubPublisherOperations pubSubPublisherOperations, String topic)
      Instantiates an outbound adapter for publishing messages to a topic.
      Parameters:
      pubSubPublisherOperations - PubSubPublisherOperations to use
      topic - short or fully qualified destination topic name
  • Method Details

    • isSync

      public boolean isSync()
    • setSync

      public void setSync(boolean sync)
      Set publish method to be synchronous or asynchronous.

      Publish is asynchronous be default.

      Parameters:
      sync - true for synchronous, false for asynchronous
    • getPublishTimeoutExpression

      public org.springframework.expression.Expression getPublishTimeoutExpression()
    • setPublishTimeoutExpression

      public void setPublishTimeoutExpression(org.springframework.expression.Expression publishTimeoutExpression)
      Set the SpEL expression to evaluate a timeout in milliseconds for a synchronous publish call to Google Cloud Pub/Sub.
      Parameters:
      publishTimeoutExpression - the Expression for the publish timeout in milliseconds
    • setPublishTimeoutExpressionString

      public void setPublishTimeoutExpressionString(String publishTimeoutExpression)
      Set the SpEL expression to evaluate a timeout in milliseconds for a synchronous publish call to Google Cloud Pub/Sub from a string.
      Parameters:
      publishTimeoutExpression - a string with an expression for the publish timeout in milliseconds
    • setPublishTimeout

      public void setPublishTimeout(long timeoutMillis)
      Set the timeout in milliseconds for a synchronous publish call to Google Cloud Pub/Sub.
      Parameters:
      timeoutMillis - timeout in milliseconds
    • getPublishCallback

      protected BiConsumer<String,Throwable> getPublishCallback()
    • setSuccessCallback

      public void setSuccessCallback(PubSubMessageHandler.SuccessCallback successCallback)
      Set callback (can be a lambda) for processing the published message ID and the original Message after the message was successfully published.
      Parameters:
      successCallback - callback accepting a String message ID and the original Message.
    • setFailureCallback

      public void setFailureCallback(PubSubMessageHandler.FailureCallback failureCallback)
      Set callback (can be a lambda) for processing the root cause exception and the original Message in case of failure.
      Parameters:
      failureCallback - callback accepting a Throwable and a Message.
    • getTopicExpression

      public org.springframework.expression.Expression getTopicExpression()
    • setTopicExpression

      public void setTopicExpression(org.springframework.expression.Expression topicExpression)
      Set the SpEL expression for the topic this adapter sends messages to.
      Parameters:
      topicExpression - the SpEL expression representing the topic name
    • setTopic

      public void setTopic(String topic)
      Set the topic where this adapter sends messages to.
      Parameters:
      topic - topic name
    • setTopicExpressionString

      public void setTopicExpressionString(String topicExpressionString)
      Set the topic expression string that is evaluated into an actual expression.
      Parameters:
      topicExpressionString - topic expression string
    • setHeaderMapper

      public void setHeaderMapper(org.springframework.integration.mapping.HeaderMapper<Map<String,String>> headerMapper)
      Set the header mapper to map headers from Message into outbound PubsubMessage.
      Parameters:
      headerMapper - the header mapper
    • handleMessageInternal

      protected void handleMessageInternal(org.springframework.messaging.Message<?> message)
      Specified by:
      handleMessageInternal in class org.springframework.integration.handler.AbstractMessageHandler
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.context.IntegrationObjectSupport