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:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
org.springframework.integration.handler.AbstractReplyProducingMessageHandler.RequestHandlerNested 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
messagingTemplateFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields 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 voiddoInit()protected ObjecthandleRequestMessage(org.springframework.messaging.Message<?> requestMessage) voidsetCommand(S3MessageHandler.Command command) Specify aS3MessageHandler.Commandto perform againstS3TransferManager.voidsetCommandExpression(org.springframework.expression.Expression commandExpression) The SpEL expression to evaluate the command to perform onS3TransferManager:upload,downloadorcopy.voidsetDestinationBucketExpression(org.springframework.expression.Expression destinationBucketExpression) The SpEL expression to evaluate the target S3 bucket for copy operation.voidsetDestinationKeyExpression(org.springframework.expression.Expression destinationKeyExpression) The SpEL expression to evaluate the target S3 key for copy operation.voidsetKeyExpression(org.springframework.expression.Expression keyExpression) The SpEL expression to evaluate S3 object key at runtime againstrequestMessage.voidsetUploadMetadataProvider(BiConsumer<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder, org.springframework.messaging.Message<?>> uploadMetadataProvider) Specify anBiConsumercallback 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, setRequiresReplyMethods 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, updateNotPropagatedHeadersMethods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods 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, shouldTrackMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods 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.Commandto perform againstS3TransferManager.- Parameters:
command- TheS3MessageHandler.Commandto use.- See Also:
-
setCommandExpression
public void setCommandExpression(org.springframework.expression.Expression commandExpression) The SpEL expression to evaluate the command to perform onS3TransferManager:upload,downloadorcopy.- Parameters:
commandExpression- the SpEL expression to evaluate theS3TransferManageroperation.- 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:
-
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:
-
setUploadMetadataProvider
public void setUploadMetadataProvider(BiConsumer<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder, org.springframework.messaging.Message<?>> uploadMetadataProvider) Specify anBiConsumercallback to populate the metadata for upload operation, e.g.Content-MD5,Content-Typeor any other required options.- Parameters:
uploadMetadataProvider- theBiConsumerto use for upload request option settings.
-
doInit
protected void doInit()- Overrides:
doInitin classorg.springframework.integration.handler.AbstractReplyProducingMessageHandler
-
handleRequestMessage
- Specified by:
handleRequestMessagein classorg.springframework.integration.handler.AbstractReplyProducingMessageHandler
-