Apache骆驼:Pollenrich不称呼动态URI

发布于 2025-01-25 03:55:36 字数 2490 浏览 1 评论 0原文

我有一条轮询服务器电子邮件的路线。在fornctROute中,我正在尝试通过emailpollingRoute中的Pollenrich方法通过IMAP协议来传递电子邮件的主题。目前,我面临着动态URI端点的问题。我注意到在调用Pollenrich方法之前正在清除标头。因此,我尝试使用$ {ExchangeProperty.Subject},但没有发送电子邮件。当我直接将主题设置为字符串中的端点时,然后将获取电子邮件。

如何在Pollenrich方法中动态设置主题?该主题正在从farnerroute传递给emailPollingRoute路由。

感谢任何帮助

@Component
public class FunctionRoute extends EmailPollingRoute {
    
    static final Logger LOGGER = LoggerFactory.getLogger(FunctionRoute.class);
    
    
    @Override
    public void configure() throws Exception {
        from("direct:process_polling_email_function")
        .process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                subject = "ABCD - Test1";
                exchange.setProperty("ABCD - Test1");
                LOGGER.info("1. subject - " + subject);
                
            }})                          
        //.setProperty("subject", constant("ABCD - Test1"))
        //.setHeader("subject", simple("ABCD - Test1"))
        .to("direct:process_polling_email");
    }

}
@Component
public class EmailPollingRoute extends BaseRouteBuilder {
    
    static final Logger LOGGER = LoggerFactory.getLogger(EmailPollingRoute.class);
        
    public String subject;
    
    @Override
    public void configure() throws Exception {
            
        //super.configure();
        //2362
    
        //@formatter:off
        from("direct:process_polling_email")
            .routeId("routeId_EmailPollingRoute")
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                
                     subject = exchange.getProperty("subject", String.class);
                     LOGGER.info("0001 - subjectB: (" + subject + ")");
                    
                }})
            
            .pollEnrich("imaps://XXXXXXX.info"
                    + "?username=XXXXX&"
                    + "password=XXXXXXX&"
                    +"folderName=Inbox/Test&"
                    +"searchTerm.fromSentDate=now-72h&"
                        +"searchTerm.subject=${exchangeProperty.subject}&"
                        +"fetchSize=1");
                    
            .to("log:newmail");
            
            //@formatter:on
        
    }
}

I have a route to poll the email from the server. In the FunctionRoute I am trying to pass the subject of the email I want to fetch by the IMAP protocol using pollEnrich method in the EmailPollingRoute. Currently I am facing problem to make a dynamic URI endpoint. I noticed the headers are being cleared before calling the pollEnrich method. Therefore I tried to use the ${exchangeProperty.subject} but there is no email is fetched. When I set the subject directly in the endpoint as String then the email is being fetched.

How can I set the subject dynamically in the pollEnrich method? The subject is being passed from the FunctionRoute to EmailPollingRoute route.

I appreciate any help

@Component
public class FunctionRoute extends EmailPollingRoute {
    
    static final Logger LOGGER = LoggerFactory.getLogger(FunctionRoute.class);
    
    
    @Override
    public void configure() throws Exception {
        from("direct:process_polling_email_function")
        .process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                subject = "ABCD - Test1";
                exchange.setProperty("ABCD - Test1");
                LOGGER.info("1. subject - " + subject);
                
            }})                          
        //.setProperty("subject", constant("ABCD - Test1"))
        //.setHeader("subject", simple("ABCD - Test1"))
        .to("direct:process_polling_email");
    }

}
@Component
public class EmailPollingRoute extends BaseRouteBuilder {
    
    static final Logger LOGGER = LoggerFactory.getLogger(EmailPollingRoute.class);
        
    public String subject;
    
    @Override
    public void configure() throws Exception {
            
        //super.configure();
        //2362
    
        //@formatter:off
        from("direct:process_polling_email")
            .routeId("routeId_EmailPollingRoute")
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                
                     subject = exchange.getProperty("subject", String.class);
                     LOGGER.info("0001 - subjectB: (" + subject + ")");
                    
                }})
            
            .pollEnrich("imaps://XXXXXXX.info"
                    + "?username=XXXXX&"
                    + "password=XXXXXXX&"
                    +"folderName=Inbox/Test&"
                    +"searchTerm.fromSentDate=now-72h&"
                        +"searchTerm.subject=${exchangeProperty.subject}&"
                        +"fetchSize=1");
                    
            .to("log:newmail");
            
            //@formatter:on
        
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给我一枪 2025-02-01 03:55:36

您可以使用简单方法动态设置Pollenrich URI,也可以以相似的方式指定超时。

.pollEnrich()
    .simple("imaps://XXXXXXX.info"
        + "?username=XXXXX&"
        + "password=XXXXXXX&"
        +"folderName=Inbox/Test&"
        +"searchTerm.fromSentDate=now-72h&"
        +"searchTerm.subject=${exchangeProperty.subject}&"
        +"fetchSize=1")
    .timeout(1000);

You can set pollEnrich URI dynamically using simple method, you can also specify timeout in similar way.

.pollEnrich()
    .simple("imaps://XXXXXXX.info"
        + "?username=XXXXX&"
        + "password=XXXXXXX&"
        +"folderName=Inbox/Test&"
        +"searchTerm.fromSentDate=now-72h&"
        +"searchTerm.subject=${exchangeProperty.subject}&"
        +"fetchSize=1")
    .timeout(1000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文