I need to handle emails from about 30 addresses. I implement this in a way where all emails going to one DirectChannel
and after to Receiver
. In Receiver
I can understand from what address is message comes, to do this I create CustomMessageSource
that wraps javax.mail.Message
to my own type that contains javax.mail.Message
and some Enum
. Looks like this is not a good decision, cause I can use @Transformer
, but how can I use it if I have only 1 channel?
That was the first question.
Second question:
Should I use ONE channel and ONE receiver for all that addresses? Or better to have channel and receiver for each mail address? I don't understand Spring so deeply to feel the difference.
p.s. this question is continuation of Spring multiple imapAdapter
In each child context, you can add a header enricher to set a custom header to the URL from the adapter; with the output channel being the shared channel to the shared service.
In the service, use
void foo(Message emailMessage, @Header("myHeader") String url)
I would generally recommend using a single service unless the service needs to do radically different things based on the source.
EDIT:
I modified my answer to your previous question to enhance the original message with the url in a header; each instance has its own header enricher and they all route the enriched message to the common
emailChannel
....and I modified the receiving service so it gets access to the header...
...hope that helps.
EDIT 2:
And this one's a bit more sophisticated; it pulls the from from the payload and puts it in a header; not needed for your use case since you have the full message, but it illustrates the technique...
and