public class SnsMessageHandler extends AbstractAwsMessageHandler<java.util.Map<java.lang.String,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.getEvaluationContext() 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(AmazonSNSAsync amazonSns) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
additionalOnSuccessHeaders(org.springframework.integration.support.AbstractIntegrationMessageBuilder<?> messageBuilder,
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(io.awspring.cloud.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, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeadershandleMessage, onComplete, onError, onNext, onSubscribebuildSendTimer, destroy, getComponentType, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitpublic SnsMessageHandler(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(io.awspring.cloud.core.env.ResourceIdResolver resourceIdResolver)
ResourceIdResolver to resolve logical topic names to physical
resource ids.resourceIdResolver - the ResourceIdResolver to use.protected void onInit()
onInit in class AbstractAwsMessageHandler<java.util.Map<java.lang.String,MessageAttributeValue>>protected java.util.concurrent.Future<?> handleMessageToAws(org.springframework.messaging.Message<?> message)
handleMessageToAws in class AbstractAwsMessageHandler<java.util.Map<java.lang.String,MessageAttributeValue>>protected void additionalOnSuccessHeaders(org.springframework.integration.support.AbstractIntegrationMessageBuilder<?> messageBuilder,
AmazonWebServiceRequest request,
java.lang.Object result)
additionalOnSuccessHeaders in class AbstractAwsMessageHandler<java.util.Map<java.lang.String,MessageAttributeValue>>