public class SnsMessageHandler extends AbstractAwsMessageHandler
AbstractAwsMessageHandler
implementation to send SNS Notifications
(AmazonSNSAsync.publishAsync(PublishRequest)
) to the provided topicArn
(or evaluated at runtime against Message
).
The SNS Message subject can be evaluated as a result of subjectExpression
.
The algorithm to populate SNS Message body is like:
payload instanceof PublishRequest
it is used as is for publishing.
bodyExpression
is specified, it is used to be evaluated
against requestMessage
.
payload
) is instance of SnsBodyBuilder
,
the SNS Message is built from there and the messageStructure
of the PublishRequest
is set to json
.
For the convenience the package org.springframework.integration.aws.support
is imported
to the AbstractAwsMessageHandler.evaluationContext
to allow bypass it for the SnsBodyBuilder
from the bodyExpression
definition. For example:
String bodyExpression =
"SnsBodyBuilder.withDefault(payload).forProtocols(payload.substring(0, 140), 'sms')";
snsMessageHandler.setBodyExpression(spelExpressionParser.parseExpression(bodyExpression));
payload
(or the bodyExpression
evaluation result) is converted
to the String
using IntegrationObjectSupport.getConversionService()
.
AmazonSNSAsync
,
PublishRequest
,
SnsBodyBuilder
DEFAULT_SEND_TIMEOUT
messagingTemplate
Constructor and Description |
---|
SnsMessageHandler(com.amazonaws.services.sns.AmazonSNSAsync amazonSns) |
Modifier and Type | Method and Description |
---|---|
protected void |
additionalOnSuccessHeaders(org.springframework.integration.support.AbstractIntegrationMessageBuilder<?> messageBuilder,
com.amazonaws.AmazonWebServiceRequest request,
java.lang.Object result) |
protected java.util.concurrent.Future<?> |
handleMessageToAws(org.springframework.messaging.Message<?> message) |
protected void |
onInit() |
void |
setBodyExpression(org.springframework.expression.Expression bodyExpression)
The
Expression to produce the SNS notification message. |
void |
setResourceIdResolver(org.springframework.cloud.aws.core.env.ResourceIdResolver resourceIdResolver)
Specify a
ResourceIdResolver to resolve logical topic names to physical resource ids. |
void |
setSubject(java.lang.String subject) |
void |
setSubjectExpression(org.springframework.expression.Expression subjectExpression) |
void |
setTopicArn(java.lang.String topicArn) |
void |
setTopicArnExpression(org.springframework.expression.Expression topicArnExpression) |
getAsyncHandler, getErrorMessageStrategy, getEvaluationContext, getFailureChannel, getSendTimeoutExpression, handleMessageInternal, isSync, obtainAsyncHandler, setAsyncHandler, setErrorMessageStrategy, setFailureChannel, setFailureChannelName, setSendTimeout, setSendTimeoutExpression, setSendTimeoutExpressionString, setSync
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, shouldCopyRequestHeaders, shouldSplitOutput
configureMetrics, getActiveCount, getActiveCountLong, getComponentType, getDuration, getErrorCount, getErrorCountLong, getHandleCount, getHandleCountLong, getManagedName, getManagedType, getMaxDuration, getMeanDuration, getMinDuration, getOrder, getOverrides, getStandardDeviationDuration, handleMessage, isCountsEnabled, isLoggingEnabled, isStatsEnabled, onComplete, onError, onNext, onSubscribe, reset, setCountsEnabled, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, setStatsEnabled
afterPropertiesSet, extractTypeIfPossible, getApplicationContext, getApplicationContextId, getBeanFactory, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public SnsMessageHandler(com.amazonaws.services.sns.AmazonSNSAsync amazonSns)
public void setTopicArn(java.lang.String topicArn)
public void setTopicArnExpression(org.springframework.expression.Expression topicArnExpression)
public void setSubject(java.lang.String subject)
public void setSubjectExpression(org.springframework.expression.Expression subjectExpression)
public void setBodyExpression(org.springframework.expression.Expression bodyExpression)
Expression
to produce the SNS notification message.
If it evaluates to the SnsBodyBuilder
the messageStructure
of the PublishRequest
is set to json
.
Otherwise the IntegrationObjectSupport.getConversionService()
is used to convert the evaluation result
to the String
without setting the messageStructure
.bodyExpression
- the Expression
to produce the SNS notification message.public void setResourceIdResolver(org.springframework.cloud.aws.core.env.ResourceIdResolver resourceIdResolver)
ResourceIdResolver
to resolve logical topic names to physical resource ids.resourceIdResolver
- the ResourceIdResolver
to use.protected void onInit() throws java.lang.Exception
onInit
in class AbstractAwsMessageHandler
java.lang.Exception
protected java.util.concurrent.Future<?> handleMessageToAws(org.springframework.messaging.Message<?> message)
handleMessageToAws
in class AbstractAwsMessageHandler
protected void additionalOnSuccessHeaders(org.springframework.integration.support.AbstractIntegrationMessageBuilder<?> messageBuilder, com.amazonaws.AmazonWebServiceRequest request, java.lang.Object result)
additionalOnSuccessHeaders
in class AbstractAwsMessageHandler