Class S3MessageHandler
- All Implemented Interfaces:
org.reactivestreams.Subscriber<org.springframework.messaging.Message<?>>
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanClassLoaderAware
,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.core.MessageProducer
,org.springframework.integration.handler.HeaderPropagationAware
,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<?>>
AbstractReplyProducingMessageHandler
implementation for the Amazon S3
services.
The implementation is fully based on the S3TransferManager
and support its
upload
, download
and copy
operations which can be determined by
the provided or evaluated via SpEL expression at runtime
S3MessageHandler.Command
.
This AbstractReplyProducingMessageHandler
can behave as a "one-way" (by
default) or "request-reply" component according to the produceReply
constructor argument.
The "one-way" behavior is also blocking, which is achieved with the
Transfer.completionFuture()
invocation. Consider to use an async upstream hand
off if this blocking behavior isn't appropriate.
The "request-reply" behavior is async and the Transfer
result from the
S3TransferManager
operation is sent to the AbstractMessageProducingHandler.getOutputChannel()
, assuming
the transfer progress observation in the downstream flow.
The TransferListener
can be supplied via AwsHeaders.TRANSFER_LISTENER
request message header to track the transfer progress. Also,
see a Transfer
API returned as a reply message from this handler.
For the upload operation the BiConsumer
callback can be supplied to
populate options on a PutObjectRequest.Builder
against request message.
For download operation the payload
must be a File
instance,
representing a single file for downloaded content or directory to download all files
from the S3 virtual directory.
An S3 Object key
for upload and download can be determined by the provided
keyExpression
or the File.getName()
is used directly. The former has
precedence.
For copy operation all keyExpression
, destinationBucketExpression
and
destinationKeyExpression
are required and must not evaluate to null
.
- Author:
- Artem Bilan, John Logan
- See Also:
-
S3TransferManager
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
org.springframework.integration.handler.AbstractReplyProducingMessageHandler.RequestHandler
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.handler.AbstractMessageProducingHandler
messagingTemplate
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorsConstructorDescriptionS3MessageHandler
(software.amazon.awssdk.services.s3.S3AsyncClient amazonS3, String bucket) S3MessageHandler
(software.amazon.awssdk.services.s3.S3AsyncClient amazonS3, String bucket, boolean produceReply) S3MessageHandler
(software.amazon.awssdk.services.s3.S3AsyncClient amazonS3, org.springframework.expression.Expression bucketExpression) S3MessageHandler
(software.amazon.awssdk.services.s3.S3AsyncClient amazonS3, org.springframework.expression.Expression bucketExpression, boolean produceReply) S3MessageHandler
(software.amazon.awssdk.transfer.s3.S3TransferManager transferManager, String bucket) S3MessageHandler
(software.amazon.awssdk.transfer.s3.S3TransferManager transferManager, String bucket, boolean produceReply) S3MessageHandler
(software.amazon.awssdk.transfer.s3.S3TransferManager transferManager, org.springframework.expression.Expression bucketExpression) S3MessageHandler
(software.amazon.awssdk.transfer.s3.S3TransferManager transferManager, org.springframework.expression.Expression bucketExpression, boolean produceReply) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doInit()
protected Object
handleRequestMessage
(org.springframework.messaging.Message<?> requestMessage) void
setCommand
(S3MessageHandler.Command command) Specify aS3MessageHandler.Command
to perform againstS3TransferManager
.void
setCommandExpression
(org.springframework.expression.Expression commandExpression) The SpEL expression to evaluate the command to perform onS3TransferManager
:upload
,download
orcopy
.void
setDestinationBucketExpression
(org.springframework.expression.Expression destinationBucketExpression) The SpEL expression to evaluate the target S3 bucket for copy operation.void
setDestinationKeyExpression
(org.springframework.expression.Expression destinationKeyExpression) The SpEL expression to evaluate the target S3 key for copy operation.void
setKeyExpression
(org.springframework.expression.Expression keyExpression) The SpEL expression to evaluate S3 object key at runtime againstrequestMessage
.void
setUploadMetadataProvider
(BiConsumer<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder, org.springframework.messaging.Message<?>> uploadMetadataProvider) Specify anBiConsumer
callback to populate the metadata for upload operation, e.g.Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
doInvokeAdvisedRequestHandler, getBeanClassLoader, getIntegrationPatternType, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply
Methods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, setupMessageProcessor, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeaders
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention
Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getComponentType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, 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, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface reactor.core.CoreSubscriber
currentContext
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
S3MessageHandler
-
S3MessageHandler
public S3MessageHandler(software.amazon.awssdk.services.s3.S3AsyncClient amazonS3, org.springframework.expression.Expression bucketExpression) -
S3MessageHandler
public S3MessageHandler(software.amazon.awssdk.services.s3.S3AsyncClient amazonS3, String bucket, boolean produceReply) -
S3MessageHandler
public S3MessageHandler(software.amazon.awssdk.services.s3.S3AsyncClient amazonS3, org.springframework.expression.Expression bucketExpression, boolean produceReply) -
S3MessageHandler
public S3MessageHandler(software.amazon.awssdk.transfer.s3.S3TransferManager transferManager, String bucket) -
S3MessageHandler
public S3MessageHandler(software.amazon.awssdk.transfer.s3.S3TransferManager transferManager, org.springframework.expression.Expression bucketExpression) -
S3MessageHandler
public S3MessageHandler(software.amazon.awssdk.transfer.s3.S3TransferManager transferManager, String bucket, boolean produceReply) -
S3MessageHandler
public S3MessageHandler(software.amazon.awssdk.transfer.s3.S3TransferManager transferManager, org.springframework.expression.Expression bucketExpression, boolean produceReply)
-
-
Method Details
-
setKeyExpression
public void setKeyExpression(org.springframework.expression.Expression keyExpression) The SpEL expression to evaluate S3 object key at runtime againstrequestMessage
.- Parameters:
keyExpression
- the SpEL expression for S3 key.
-
setCommand
Specify aS3MessageHandler.Command
to perform againstS3TransferManager
.- Parameters:
command
- TheS3MessageHandler.Command
to use.- See Also:
-
setCommandExpression
public void setCommandExpression(org.springframework.expression.Expression commandExpression) The SpEL expression to evaluate the command to perform onS3TransferManager
:upload
,download
orcopy
.- Parameters:
commandExpression
- the SpEL expression to evaluate theS3TransferManager
operation.- See Also:
-
setDestinationBucketExpression
public void setDestinationBucketExpression(org.springframework.expression.Expression destinationBucketExpression) The SpEL expression to evaluate the target S3 bucket for copy operation.- Parameters:
destinationBucketExpression
- the SpEL expression for destination bucket.- See Also:
-
S3TransferManager.copy(CopyRequest)
-
setDestinationKeyExpression
public void setDestinationKeyExpression(org.springframework.expression.Expression destinationKeyExpression) The SpEL expression to evaluate the target S3 key for copy operation.- Parameters:
destinationKeyExpression
- the SpEL expression for destination key.- See Also:
-
S3TransferManager.copy(CopyRequest)
-
setUploadMetadataProvider
public void setUploadMetadataProvider(BiConsumer<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder, org.springframework.messaging.Message<?>> uploadMetadataProvider) Specify anBiConsumer
callback to populate the metadata for upload operation, e.g.Content-MD5
,Content-Type
or any other required options.- Parameters:
uploadMetadataProvider
- theBiConsumer
to use for upload request option settings.
-
doInit
protected void doInit()- Overrides:
doInit
in classorg.springframework.integration.handler.AbstractReplyProducingMessageHandler
-
handleRequestMessage
- Specified by:
handleRequestMessage
in classorg.springframework.integration.handler.AbstractReplyProducingMessageHandler
-