***strong text***I want to use 2 aws outbound adaptor in a single integration flow. One is outbound S3 adaptor and one outbound SQS adaptor. I have to move file from smb share to S3 bucket then use the transformer and then use the SQS adaptor to send transformed message to SQS queue. I can achieve this with 2 integration flow but I want to achieve this with only one integration flow. If I add both outbound adaptor part of one flow only one of them is working
1 Answers
That’s true, two Outbound channel Adapters can’t work one after another. Just because one-way component doesn’t return anything to send as a payload into the output channel.
You might need to make yourself familiar with the publish-subscribe
pattern: https://www.enterpriseintegrationpatterns.com/patterns/messaging/PublishSubscribeChannel.html.
In the IntegrationFlow
you just need to configure a publishSubscribeChannel
with two subscribers as sub-flows for your different Channel Adapters.
See docs for more info: https://docs.spring.io/spring-integration/docs/5.1.7.RELEASE/reference/html/#java-dsl-subflows
UPDATE
Since you already have an .enrichHeaders(h->h.header("bucketName”,”mybucket”))
before publishSubscribeChannel()
, it is a fact that this one is going to be available for both subscribers downstream.
To make access into it from the s3MessageHandler
, you must configure it like this:
public MessageHandler s3MessageHandler() {
S3MessageHandler handler = new S3MessageHandler(amazonS3,
new FunctionExpression<>(m -> m.getHeaders().get(”mybucket”)));
return handler;
}
To make access to that header for your next SQS subscriber part, you need to change your transform()
method signature to accept the whole Message<>
, so you get access to headers again for building some custom message for SQS.