public class SnsMessageHandler
extends org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler
implementation to send SNS Notifications
(AmazonSNS.publish(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 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()
.
If this AbstractReplyProducingMessageHandler
is configured with produceReply
as
true
, the reply message is composed to be sent to the outputChannel
or
replyChannel
. The reply message's payload
is exactly the PublishRequest
object, which has been just published to SNS. Also this message has AwsHeaders.TOPIC
and AwsHeaders.SNS_PUBLISHED_MESSAGE_ID
headers to track published SNS message in the
downstream.
AmazonSNS
,
PublishRequest
,
SnsBodyBuilder
Constructor and Description |
---|
SnsMessageHandler(AmazonSNS amazonSns) |
SnsMessageHandler(AmazonSNS amazonSns,
boolean produceReply) |
Modifier and Type | Method and Description |
---|---|
protected void |
doInit() |
protected java.lang.Object |
handleRequestMessage(org.springframework.messaging.Message<?> requestMessage) |
void |
setBodyExpression(org.springframework.expression.Expression bodyExpression)
The
Expression to produce the SNS notification message. |
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) |
doInvokeAdvisedRequestHandler, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply
getOutputChannel, produceOutput, sendOutputs, setOutputChannel, setOutputChannelName, setSendTimeout, shouldCopyRequestHeaders, shouldSplitOutput
configureMetrics, getActiveCount, getActiveCountLong, getComponentType, getDuration, getErrorCount, getErrorCountLong, getHandleCount, getHandleCountLong, getManagedName, getManagedType, getMaxDuration, getMeanDuration, getMinDuration, getOrder, getStandardDeviationDuration, handleMessage, isCountsEnabled, isLoggingEnabled, isStatsEnabled, reset, setCountsEnabled, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, setStatsEnabled
afterPropertiesSet, extractTypeIfPossible, getApplicationContext, getApplicationContextId, getBeanFactory, getChannelResolver, getComponentName, getConversionService, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setTaskScheduler, toString
public SnsMessageHandler(AmazonSNS amazonSns)
public SnsMessageHandler(AmazonSNS amazonSns, boolean produceReply)
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.protected void doInit()
doInit
in class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
protected java.lang.Object handleRequestMessage(org.springframework.messaging.Message<?> requestMessage)
handleRequestMessage
in class org.springframework.integration.handler.AbstractReplyProducingMessageHandler