What is the appropriate way to trigger spring-integration int-mail:inbound-channel-adapter?

StackOverflow https://stackoverflow.com/questions/20116942

  •  03-08-2022
  •  | 
  •  

質問

First of all to clarify: I'm new to spring-integration.

I want to receive mails via an pop3-channel. I know and (think so) understand the poller mechanics. But I also want to trigger the question for new mail by a client-event. Can this be done by a Gateway or an event or a special service-locator?

Thank you brave helpers!

役に立ちましたか?

解決

Don't want to find similar solution, which I showed earlier, even on SO. But as you say that you are newbie, so I just provide the solution for you.

Well, supose you have something like this now:

<int-mail:inbound-channel-adapter store-uri="pop3:foo"
                              channel="channel">
      <int:poller fixed-rate="60000"/>
</int-mail:inbound-channel-adapter>

On the background that configuration provides a bean for Pop3MailReceiver. To get worked you solution you should change <int-mail:inbound-channel-adapter/> to this config:

<beans:bean id="pop3MailReceiver" class="org.springframework.integration.mail.Pop3MailReceiver"/>

<int:inbound-channel-adapter channel="getEmailsChannel" expression="''">
    <int:poller fixed-rate="60000"/>
</int:inbound-channel-adapter>

<int:service-activator input-channel="getEmailsChannel" output-channel="processEmailsChannel"
                               expression="@pop3MailReceiver.receive()"/>
  1. Of course, you should provide appropriate properties to the Pop3MailReceiver
  2. Generic <int:inbound-channel-adapter> triggers your Pop3MailReceiver as it is in your case already invoking <int:service-activator>
  3. <int:service-activator>, in turn, just poll mail messages from POP3.

One point to pay attention, that MailReceiver#receive() returns an array of mail messages, so maybe there is need to split it after receiving, to be consistent with <int-mail:inbound-channel-adapter/>.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top