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 ClassesModifier and TypeClassDescriptionstatic interfaceImplement this callback to post-process a message that failed to publish to Cloud Pub/Sub.static interfaceImplement 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, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionPubSubMessageHandler(PubSubPublisherOperations pubSubPublisherOperations, String topic) Instantiates an outbound adapter for publishing messages to a topic. -
Method Summary
Modifier and TypeMethodDescriptionprotected BiConsumer<String,Throwable> org.springframework.expression.Expressionorg.springframework.expression.Expressionprotected voidhandleMessageInternal(org.springframework.messaging.Message<?> message) booleanisSync()protected voidonInit()voidsetFailureCallback(PubSubMessageHandler.FailureCallback failureCallback) Set callback (can be a lambda) for processing the root cause exception and the originalMessagein case of failure.voidsetHeaderMapper(org.springframework.integration.mapping.HeaderMapper<Map<String, String>> headerMapper) Set the header mapper to map headers fromMessageinto outboundPubsubMessage.voidsetPublishTimeout(long timeoutMillis) Set the timeout in milliseconds for a synchronous publish call to Google Cloud Pub/Sub.voidsetPublishTimeoutExpression(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.voidsetPublishTimeoutExpressionString(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.voidsetSuccessCallback(PubSubMessageHandler.SuccessCallback successCallback) Set callback (can be a lambda) for processing the published message ID and the originalMessageafter the message was successfully published.voidsetSync(boolean sync) Set publish method to be synchronous or asynchronous.voidSet the topic where this adapter sends messages to.voidsetTopicExpression(org.springframework.expression.Expression topicExpression) Set the SpEL expression for the topic this adapter sends messages to.voidsetTopicExpressionString(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, setObservationConventionMethods 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, shouldTrackMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
PubSubMessageHandler
Instantiates an outbound adapter for publishing messages to a topic.- Parameters:
pubSubPublisherOperations-PubSubPublisherOperationsto usetopic- 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- theExpressionfor the publish timeout in milliseconds
-
setPublishTimeoutExpressionString
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
-
setSuccessCallback
Set callback (can be a lambda) for processing the published message ID and the originalMessageafter the message was successfully published.- Parameters:
successCallback- callback accepting aStringmessage ID and the originalMessage.
-
setFailureCallback
Set callback (can be a lambda) for processing the root cause exception and the originalMessagein case of failure.- Parameters:
failureCallback- callback accepting aThrowableand aMessage.
-
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
Set the topic where this adapter sends messages to.- Parameters:
topic- topic name
-
setTopicExpressionString
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 fromMessageinto outboundPubsubMessage.- Parameters:
headerMapper- the header mapper
-
handleMessageInternal
protected void handleMessageInternal(org.springframework.messaging.Message<?> message) - Specified by:
handleMessageInternalin classorg.springframework.integration.handler.AbstractMessageHandler
-
onInit
protected void onInit()- Overrides:
onInitin classorg.springframework.integration.context.IntegrationObjectSupport
-