How should I build my Messages in Spring Integration?

孤街浪徒 提交于 2019-12-01 23:31:10

Actually, there is MessageBuilder support in the Spring Integration.

The general purpose of such Frameworks is to help back-end developers to decouple their domain code from messaging infrastructure. Finally, to work with Spring Integration you need to follow the POJO and Method Invocation principles.

You write your own services, transformers and domain models. Then you just use some out of the box compoenents (e.g. <int-file:inbound-channel-adapter>) and just refer from there to your POJOs, but not vise versa.

I recommend you to read Spring Integration in Action book to have more pictures on the matter.

Can you explain the reason to get deal with Spring Integration components directly?

UPDATE

1) Breaking a file into many lines of Messages

The <splitter> is for you. You should write some POJO which returns List<String> - the lines from your file without header and footer. How to read lines from File isn't a task of Spring Integration. Especially, if the "line" is something logical, not the real file line.

2) Converting Messages into Messages

One more time: there is no reason to build Message object. It's just enough to build new payload in some transformer (again POJO) and framework wrap to its Message to send.

Payload Type Router speaks for itself: it checks a payload type, but not Message type. Of course, payload can be Message too, and even any header can be as well.

Anyway your Builder snapshot shows exactly a creation of plain Spring Integration Message in the end. And as I said: it will be enough just to transform one payload to another and return it from some POJO, which you will use as a transformer reference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!