Reputation: 21
I am a newbie to the Spring Integration framework, so I have questions regarding my current workflow that I need to implement. Not sure how to do proper modeling for that. Here are the steps that need to be done:
<user>
<name>Steve</name>
<email>[email protected]</email>
<dateOfBirth>01.01.1990</dateOfBirth>
<documents>
<document>
<fileName>test.pdf</fileName>
</document>
<document>
<fileName>test.mp3</fileName>
</document>
<document>
<fileName>image.png</fileName>
</document>
<document>
<fileName>test2.pdf</fileName>
</document>
</documents>
</user>
documents
element
whether those (pdf, mp3, images...) exist in the polling directory.
If not throw an error and change the extension of the XML file.Is this a good use case for Spring Integration? I am not sure how to model this workflow correctly. Can you please give me some tips?
Thanks in advance
Upvotes: 2
Views: 47
Reputation: 121177
Your design is correct and it is indeed a fact that Spring Integration with all of its EIP implementations, including MessageChannel
abstraction and a set of protocol-specific channel adapters and gateways can help to implement any possible task in the enterprise.
We can't implement everything for you over here. Plus some of the items in your question may deserve their own SO threads. But I'll try to give you some links where to look for info which may help you to proceed with your solution.
First of all it would be great if you have read a EIP Book to understand all the terminology and possible components in the library you are going to use.
Then you go to Spring Integration Reference Manual and scan it for components which can help you to implement particular task in your design.
Let's see what is possible according your description and requests!
You can poll local file system for new files using a FileReadingMessageSource
: https://docs.spring.io/spring-integration/docs/current/reference/html/file.html#file-reading
To get a content of that XML file, especially a <documents>
tag, you can use an XPathTransformer
: https://docs.spring.io/spring-integration/docs/current/reference/html/xml.html#xml-xpath-transformer. Then you split it into a list of file names: https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#splitter. The next one should be a plain transformer to create a java.io.File
object or FileInputStream
or its byte[]
: https://docs.spring.io/spring-integration/docs/current/reference/html/message-transformation.html#messaging-transformation-chapter.
We are not sure how you connect with the third-party system, so, please, be sure that you know what to choose for network interaction. It may be a regular REST service, so you use an HttpRequestExecutingMessageHandler
, a TcpOutboundGateway
if it is plain TCP/IP connection and so on. You really can find enough of protocol-specific channel adapter implementations in Spring Integration: https://docs.spring.io/spring-integration/docs/current/reference/html/endpoint-summary.html#spring-integration-endpoints.
& 5. Looks more like you need to deal with XML unmarshalling and marshaling in the end: https://docs.spring.io/spring-integration/docs/current/reference/html/xml.html#xml-transformation
For error handling you may consider to wrap some calls into a @MessagingGateway
with its errorChannel
support: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway. Or just add an ExpressionEvaluatingRequestHandlerAdvice
to the particular endpoint to simulate a try..catch
exactly on that specific logic: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#message-handler-advice-chain
See also Spring Integration Samples for some ideas.
You probably going to have more questions, but please, consider to have them as individual most specific SO threads, so we won't pollute this one for non-relevant info.
Upvotes: 1