2014-02-13 62 views
0

我正在構建WSO2 ESB 4.8.1以接收傳入的二進制消息並將其存儲到具有VFS的磁盤。我可以使用Send mediator將消息存儲到文件中,但由於這是非阻塞中介,所以剩下的序列將繼續同步。這導致存儲文件需要更多時間的大文件出現問題。WSO2 ESB阻塞vfs可能嗎?

問題:是否可以使用Callout mediator或其他阻止機制存儲文件,以便在VFS完全存儲文件後ESB將繼續處理序列?我試過標註調解器,但它不支持vfs端點url,例如「vfs:file:/// tmp」

感謝您的任何提示。

回答

1

通過創建一個自定義Class中介來解決這個問題,該中介採用數據並將其傳輸到文件中。課堂調解員完成作業後,課程將繼續進行。

這裏的類中介代碼:

public class FileSaveMediator extends AbstractMediator { 

    boolean traceOn = false; 
    boolean traceOrDebugOn = false; 


    public boolean mediate(MessageContext context) { 

     traceOn = isTraceOn(context); 
     traceOrDebugOn = isTraceOrDebugOn(traceOn); 

     traceOrDebug(traceOn, "Start : FileSaveMediator"); 

     // Get property "fileuri" from synapse context 
     String fileuri = (String)context.getProperty("fileuri"); 

     SOAPBody body = context.getEnvelope().getBody(); 

      OMText binaryNode = (OMText) (body.getFirstElement()).getFirstOMChild(); 
      DataHandler actualDH; 
      actualDH = (DataHandler) binaryNode.getDataHandler(); 

      FileOutputStream fos = null; 
      try { 
       fos = new FileOutputStream(fileuri); 
       actualDH.writeTo(fos);   

      } catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 

      // Clear Body after saving file by setting dummy tags. 

      try { 
      body.setFirstChild(AXIOMUtil.stringToOM("<p></p>")); 
     } catch (XMLStreamException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } finally { 

      // Finally make sure that fileoutstream is closed 
      if (fos!=null) 
       try { 
        fos.close(); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
     } 

     traceOrDebug(traceOn, "End : FileSaveMediator"); 

     return true; 

    }