【发布时间】:2020-05-27 21:20:19
【问题描述】:
我在 Springboot 应用程序中使用以下代码:
@Bean
public IntegrationFlow mailListener() {
return IntegrationFlows.from(Mail.imapInboundAdapter(receiver()), e -> e.poller(Pollers.fixedRate(60000)))
.<Message>handle(message -> logMail(message)).get();
}
private org.springframework.messaging.Message<?> logMail(org.springframework.messaging.Message<?> message) {
System.out.println("received a mail********** !");
// System.out.println(message.getPayload());
// process message
return message;
}
@Bean
public ImapMailReceiver receiver() {
ImapMailReceiver receiver = new ImapMailReceiver(
"imaps://username:pwd@mail.company.com/INBOX");
receiver.setShouldMarkMessagesAsRead(true);
receiver.setJavaMailProperties(javaMailProperties());
return receiver;
}
private Properties javaMailProperties() {
Properties javaMailProperties = new Properties();
/*
* javaMailProperties.setProperty("mail.imap.socketFactory.class",
* "javax.net.ssl.SSLSocketFactory");
* javaMailProperties.setProperty("mail.imap.socketFactory.fallback","false");
* javaMailProperties.setProperty("mail.store.protocol","imaps");
*/
// javaMailProperties.setProperty("mail.debug","true");
return javaMailProperties;
}
我的要求是每个 Pollers.fixedRate(比如每 1 分钟)有多少新邮件到达,logMail 应该通过传递新邮件作为参数来执行多次(在下一次轮询之前)但它没有发生。每个 Pollers.fixedRate(每 1 分钟)仅调用一次 logMail 方法,因此只有一封邮件得到处理。如果我在过去 1 分钟内收到了 3 封邮件,那么现在将处理第一封邮件。第二封邮件将在接下来的 1 分钟内处理,以此类推。
或者有什么方法可以通过发送在该期间(1 分钟)内新到达的消息列表来调用 logMail 吗?你能告诉我怎么做吗?
【问题讨论】:
标签: java spring-integration jakarta-mail spring-dsl