2017-05-15 64 views
2

我正在使用以下處理器獲取電子郵件的第一個附件並將其上載到ftp服務器。Apache Camel將電子郵件附件上載到ftp

路由配置

<from uri="imaps://... 
<to uri="ejb:java:global/Dms/MailProcessor"/> 
<to uri="ftp://.... 

MailProcessor

@Named("MailProcessor") 
@Stateless 
public class MailProcessor implements Processor { 

    @Override 
    public void process(Exchange exchange) throws Exception { 

     exchange.getOut().setHeaders(exchange.getIn().getHeaders()); 

     Map<String, DataHandler> attachments = exchange.getIn().getAttachments(); 
     if (attachments.size() > 0) { 
      for (String name : attachments.keySet()) { 
       DataHandler dataHandler = attachments.get(name); 

       // SET ATTACHMENT FILENAME TO OUTPUT FILENAME HEADER 
       String filename = dataHandler.getName(); 
       filename = MimeUtility.decodeText(filename); 
       exchange.getOut().setHeader("filename", filename); 

       // SET INPUT ATTACHMENT TO OUTPUT BODY 
       byte[] data = exchange.getContext().getTypeConverter().convertTo(byte[].class, dataHandler.getInputStream()); 
       exchange.getOut().setBody(data); 

       // SET ONLY THE FIRST ATTACHMENT 
       break; 
      } 
     }else{ 
      exchange.getOut().setBody(exchange.getIn().getBody()); 
    } 

} 

這工作一般,但它需要從字面上永遠爲 「大」 的附件。 (一半僅有5兆附件一小時)

登錄

TRACE [org.apache.camel.component.file.remote.FtpOperations] (Camel (example) thread #119 - imaps://mail.example.com) Changing directory: upload 
TRACE [org.apache.camel.component.file.remote.FtpOperations] (Camel (example) thread #119 - imaps://mail.example.com) doStoreFile(ID-example-local-59752-1494841993139-21-11) 
DEBUG [org.apache.camel.component.file.remote.FtpOperations] (Camel (example) thread #119 - imaps://mail.example.com) About to store file: ID-example-local-59752-1494841993139-21-11 using stream: [email protected] 
TRACE [org.apache.camel.component.file.remote.FtpOperations] (Camel (example) thread #119 - imaps://mail.example.com) Client storeFile: ID-example-local-59752-1494841993139-21-11 
-- long pause -- 

我也試圖這樣轉換附件:

byte[] data = exchange.getContext().getTypeConverter().convertTo(byte[].class, dataHandler.getInputStream()); 
exchange.getOut().setBody(data); 

,但是這給了我以下:

2017-05-15 11:23:20,968 TRACE [org.apache.camel.impl.converter.DefaultTypeConverter] (Camel (example) thread #133 - imaps://mail.example.com) Converting org.apache.camel.Processor$$$view63 -> org.apache.camel.Processor with value: Proxy for view class: org.apache.camel.Processor of EJB: MailProcessor 
2017-05-15 11:23:20,968 TRACE [org.apache.camel.component.bean.BeanProcessor] (Camel (example) thread #133 - imaps://mail.example.com) Using a custom adapter as bean invocation: Proxy for view class: org.apache.camel.Processor of EJB: MailProcessor 
2017-05-15 11:23:20,990 TRACE [org.apache.camel.impl.converter.DefaultTypeConverter] (Camel (example) thread #133 - imaps://mail.example.com) Converting com.sun.mail.util.BASE64DecoderStream -> byte[] with value: [email protected] 
2017-05-15 11:23:20,990 TRACE [org.apache.camel.impl.converter.DefaultTypeConverter] (Camel (example) thread #133 - imaps://mail.example.com) Using converter: StaticMethodTypeConverter: public static byte[] org.apache.camel.converter.IOConverter.toBytes(java.io.InputStream) throws java.io.IOException to convert [class com.sun.mail.util.BASE64DecoderStream=>class [B] 
2017-05-15 11:23:20,990 TRACE [org.apache.camel.util.IOHelper] (Camel (example) thread #133 - imaps://mail.example.com) Copying InputStream: [email protected] -> OutputStream: with buffer: 4096 and flush on each write false 
-- long pause -- 

使用Fil上傳到ftp服務器ezilla就像一個魅力。另外,當我在其他路由中使用camel-ftp(由文件上傳觸發)時,上傳到ftp服務器的工作速度非常快。 所以我有一種感覺,就是附件的轉換會減慢速度。

問題:

是我的假設是正確的,我怎麼能加快速度?

回答