1

Have a spring integration application where files are routed from a folder to S3 buckets using s3-outbound-channel-adapter. If the file processed successfully, then file will be moved to corresponding target-bucket. if any error , file move to error bucket via error channel.

Have to generate a daily statistics report in a text file containing below details.

Total no of files processed: Total success : Total Error:

Would like to know how to get no of files processed successfully/error. Is there any way to achieve this requirement.

Any suggestion or example would be helpful.

Gone through the DefaultMessageChannelMetrics and Micrometer Integration in documentation. Not sure it will help my requirement.

Have separate gateway and adapter to process success and error files.

Success :

<int-aws:s3-outbound-gateway id="s3FileMover"
        request-channel="filesOutS3GateWay"
        reply-channel="filesOutS3ChainChannel"
        transfer-manager="transferManager"
        bucket-expression = "headers.TARGET_PATH"
        key-expression="headers.file_name"
        command="UPLOAD">
        <int-aws:request-handler-advice-chain>
            <ref bean="retryAdvice" />
        </int-aws:request-handler-advice-chain>
    </int-aws:s3-outbound-gateway>

Error :

<int-aws:s3-outbound-channel-adapter id="filesErrorS3Mover"
            channel="filesErrorS3MoverChannel"
            transfer-manager="transferManager"
            bucket="${aws.s3.error.bucket}"
             key-expression="headers.TARGET + '/' + headers.file_name"
            upload-metadata-provider = "fileMetaDataProvider"
            command="UPLOAD">
            <int-aws:request-handler-advice-chain>
                <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
                    <property name="onSuccessExpressionString" value="payload.delete()"/>
                </bean>
            </int-aws:request-handler-advice-chain>
Jessie
  • 963
  • 5
  • 16
  • 26

1 Answers1

1

You can query and reset the MessageChannelMetrics directly on the message channels directly.

getSendCount();
reset();

All standard message channels implement that interface so just inject the channel as that...

@Autowired
private MessageChannelMetrics filesOutS3GateWay;

private int getCount() {
    return this.filesOutS3GateWay.getSendCount();
}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thank you. Can you share some examples link how to achieve it.. observed that MessageChannelMetrics is an interface. Would like to know how to implement the getSendCount methods... Not sure if I got your point correctly. – Jessie Nov 19 '18 at 16:15
  • All standard channels implement it; I edited the answer. – Gary Russell Nov 19 '18 at 18:09