【问题标题】:Can ayone share a DSL equivalent of the Mail Attachment Sample?任何人都可以共享邮件附件示例的 DSL 等价物吗?
【发布时间】:2015-04-17 20:50:18
【问题描述】:

我第一次考虑使用 spring 集成:spring 集成示例中的邮件附件示例是一个好的开始,我今天已经为自己的目的轻松地扩展了。

但是,我更喜欢在滚动时使用 DSL,但是在研究了 DSL 示例后,我有些迷茫,因为它们非常复杂。

如果有人可以分享任何 spring 集成示例的 DSL 重新实现,或者提供一些关于如何重新实现邮件附件示例的提示,我将不胜感激。

【问题讨论】:

  • 我用java 1.7成功实现了DSL

标签: spring-integration dsl


【解决方案1】:

目前还没有该示例的 DSL 版本,但也许一个很好的起点是DSL mail test cases?

【讨论】:

  • 谢谢@gary,我确实设法拼凑了一些东西。从现在开始,我将参考那些测试。
  • 谢谢 - 如果您想将代码贡献给邮件示例,请参阅 the guidelines。
【解决方案2】:

我成功地使用 java 1.7 用 DSL 重新实现了它。以下是有趣的部分:

@Bean
public IntegrationFlow polledEmails() {

    return IntegrationFlows
        .from(
            Mail.imapInboundAdapter( "imaps://" + user + ":" + password + "@imap.gmail.com:" + imapPort + "/inbox" )
                .javaMailProperties( javaMailProperties() )
                .shouldDeleteMessages( true )
        )
        .channel( MessageChannels.direct( "incomingEmail") )
        .get();
}

@Bean
public IntegrationFlow extractAttachments() {

    return IntegrationFlows
        .from( "incomingEmail" )
        .transform( new EmailTransformer() , "transformit" )
        .split( new EmailSplitter() , "splitIntoMessages" )
        .channel( MessageChannels.direct( "attachments") )
        .get();
}

@Bean
public IntegrationFlow writeAttachmentAsFile() {

    return IntegrationFlows
        .from( "attachments" )
        // save attachment to file
        .handle( 
            Files.outboundAdapter( "'target/out/' + headers.directory" )
            .autoCreateDirectory( true ) )
        .get();
}

@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata poller() {
    return Pollers.fixedDelay( 5000 ).get();
}

private Properties javaMailProperties() {

    final Properties properties = new Properties();
    properties.put( "mail.store.protocol" , "pop3" );
    properties.put( "mail.debug" , "false" );

    return properties;
}

【讨论】:

    猜你喜欢
    • 2011-12-02
    • 2015-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多