public class SnsMessageHandler extends AbstractAwsMessageHandler<java.util.Map<java.lang.String,com.amazonaws.services.sns.model.MessageAttributeValue>>
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,
SnsBodyBuilderDEFAULT_SEND_TIMEOUTmessagingTemplateEXPRESSION_PARSER, logger| 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) |
doSetHeaderMapper, getAsyncHandler, getErrorMessageStrategy, getEvaluationContext, getFailureChannel, getHeaderMapper, getSendTimeoutExpression, handleMessageInternal, isSync, obtainAsyncHandler, setAsyncHandler, setErrorMessageStrategy, setFailureChannel, setFailureChannelName, setHeaderMapper, setSendTimeout, setSendTimeoutExpression, setSendTimeoutExpressionString, setSyncaddNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeadersconfigureMetrics, getActiveCount, getActiveCountLong, getComponentType, getDuration, getErrorCount, getErrorCountLong, getHandleCount, getHandleCountLong, getManagedName, getManagedType, getMaxDuration, getMeanDuration, getMinDuration, getOrder, getOverrides, getStandardDeviationDuration, handleMessage, isCountsEnabled, isLoggingEnabled, isStatsEnabled, onComplete, onError, onNext, onSubscribe, registerMetricsCaptor, reset, setCountsEnabled, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, setStatsEnabledafterPropertiesSet, extractTypeIfPossible, getApplicationContext, getApplicationContextId, getBeanFactory, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic 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.util.Map<java.lang.String,com.amazonaws.services.sns.model.MessageAttributeValue>>java.lang.Exceptionprotected java.util.concurrent.Future<?> handleMessageToAws(org.springframework.messaging.Message<?> message)
handleMessageToAws in class AbstractAwsMessageHandler<java.util.Map<java.lang.String,com.amazonaws.services.sns.model.MessageAttributeValue>>protected void additionalOnSuccessHeaders(org.springframework.integration.support.AbstractIntegrationMessageBuilder<?> messageBuilder,
com.amazonaws.AmazonWebServiceRequest request,
java.lang.Object result)
additionalOnSuccessHeaders in class AbstractAwsMessageHandler<java.util.Map<java.lang.String,com.amazonaws.services.sns.model.MessageAttributeValue>>