Apache camel 邮件检查是否未获取任何消息

Apache camel mail check if no message is fetched

使用 Apache Camel,我每 15 分钟获取一个电子邮件收件箱,并将电子邮件正文路由到休息端点。一切正常。 这是我的 Poller 的声明:

        from(mailServer + "?" +
            "username=" + mailUsername + "&" +
            "password=" + mailPassword + "&" +
            "consumer.delay=" + EVERY_15_MINUTES)
            .routeId("mainPoller")
            .filter(exchange -> exchange.getIn().getHeader("subject", StringUtils.EMPTY, String.class).contains(mailSubject))
            .to("activemq:send.details");

现在我需要做的是,如果没有获取消息(因为没有收到新电子邮件)我想记录一条消息.. 如何检查是否提取了 0 条消息? 谢谢:)

您可以使用 sendEmptyMessageWhenIdle 选项

Camel 2.9: If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

http://camel.apache.org/polling-consumer.html(pop3和imap是定时轮询组件)

    from(mailServer + "?" +
        "username=" + mailUsername + "&" +
        "password=" + mailPassword + "&" +
        "consumer.delay=" + EVERY_15_MINUTES+
        "&sendEmptyMessageWhenIdle=true")
        .routeId("mainPoller")
        .filter(exchange -> exchange.getIn().getHeader("subject", StringUtils.EMPTY, String.class).contains(mailSubject))
        .to("activemq:send.details");