如何在MULE中使wmq与java代码兼容

如何在MULE中使wmq与java代码兼容,mule,Mule,这是我在Mule中的xml部分。> <flow name="CatalogueFlow_BC" doc:name="CatalogueFlow_BC"> < wmq:inbound-endpoint queue="${wmq.queue.nameCT_BC}" connector-ref="WMQ" doc:name="WMQ"/> < object-to-string-transformer doc:name="File Mapping"/>

这是我在Mule中的xml部分。>

<flow name="CatalogueFlow_BC" doc:name="CatalogueFlow_BC">
   < wmq:inbound-endpoint queue="${wmq.queue.nameCT_BC}" connector-ref="WMQ" doc:name="WMQ"/>
   < object-to-string-transformer doc:name="File Mapping"/>
   < custom-transformer class="catalogue.ServiceController_BC" doc:name="Java"/>
    <logger message="******************Entered Catalogue SOAP File with Province Name BC is Processed*********" level="INFO" category="Audit_LogCAT" doc:name="CAT Logger"/>
    <catch-exception-strategy doc:name="Catch Exception Strategy">
        logger message="*******************************Entered Catalogue SOAP File with Province Name BC is having error: #[exception.causeException]****************" level="INFO" category="Audit_LogCAT" doc:name="CAT Exception Logger"/>
  /catch-exception-strategy>
</flow>



/捕获异常策略>
我的java代码正在将来自队列的SOAP消息转换为文本文件。它的设计方式是,2条SOAp消息将生成一个包含2条SOAp记录的文本文件。 问题是,当我运行mule流并将消息一个接一个地放入队列时,一切都很好。但是,如果我直接将2条消息放入队列,即首先将2条消息放入队列,然后运行流,它只接受第一个SOAP,在java转换后,第一个SOAP的结果是在文本文件中打印2次

public class IPController_BC extends AbstractMessageTransformer{
    TimeOut timeOut = TimeOut.getInstance();
    @SuppressWarnings({ "unused" })
    public Object transformMessage(MuleMessage message, String outputEncoding)throws TransformerException {
            String flagGetPayload = null;
            String intermediateFile = null;
            String invoiceFile = null;

        try {
            // Get the payload from the mule message and store in the flagGetPayload
                flagGetPayload= (String) message.getPayload();
                try{
                    Properties prop = new Properties();
                    prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("path_config.properties"));                    
                    intermediateFile = prop.getProperty("INTERMEDIATEIP_LOCATION");
                    invoiceFile=prop.getProperty("INVOICEIP_LOCATION");
                    } catch (IOException e1) {
                    // TODO Auto-generated catch block
                        logger.error("IOException",e1);
                    }

                //WRITING MESSAGE INTO A FILE FROM flagGetPayload
                File file = new File(intermediateFile+"/soap.xml");
                // if file doesnt exists, then create it
                if (!file.exists()) {
                    file.createNewFile();
                }    
                FileWriter fw = new FileWriter(file.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(flagGetPayload);
                bw.close();
                //
                String ProvinceName="BC";
                InterchangeablePriority ip=new InterchangeablePriority();
                System.out.println("start operation");
                ip.startOperationIP(ProvinceName);
                //ip.deleteFile();

                }   
                    catch (Exception e) {
                        logger.error("Exception",e);
                    }


             File folder = new File(invoiceFile);
                File[] listOfFiles = folder.listFiles();

                for (File file : listOfFiles){
                }
                String file = null;
                    for (int i = 0; i < listOfFiles.length; i++) {
                      if (listOfFiles[i].isFile()) {
                         file= listOfFiles[i].getAbsolutePath();
                      } else if (listOfFiles[i].isDirectory()) {
                      }
                    }
                    return file;
    }
    public TimeOut setTimer() {


        timeOut.schedule(30);
        return timeOut;
    }
}
公共类IPController\u BC扩展AbstractMessageTransformer{
TimeOut=TimeOut.getInstance();
@SuppressWarnings({“未使用”})
公共对象transformMessage(多消息消息、字符串输出编码)引发TransformerException{
字符串flagGetPayload=null;
字符串中间文件=null;
字符串invoiceFile=null;
试一试{
//从mule消息获取有效负载并存储在flagGetPayload中
flagGetPayload=(字符串)message.getPayload();
试一试{
Properties prop=新属性();
prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(“path_config.properties”);
intermediateFile=prop.getProperty(“INTERMEDIATEIP_位置”);
invoiceFile=prop.getProperty(“INVOICEIP_位置”);
}捕获(IOE1异常){
//TODO自动生成的捕捉块
记录器错误(“IOException”,e1);
}
//从flagGetPayload将消息写入文件
File File=新文件(mediatefile+“/soap.xml”);
//如果文件不存在,则创建它
如果(!file.exists()){
createNewFile();
}    
FileWriter fw=新的FileWriter(file.getAbsoluteFile());
BufferedWriter bw=新的BufferedWriter(fw);
写入(flagGetPayload);
bw.close();
//
字符串ProvinceName=“BC”;
InterchangablePriority ip=新的InterchangablePriority();
System.out.println(“启动操作”);
ip.startOperationIP(省名);
//deleteFile();
}   
捕获(例外e){
错误(“异常”,e);
}
文件夹=新文件(发票文件);
File[]listOfFiles=folder.listFiles();
对于(文件:listOfFiles){
}
字符串文件=null;
for(int i=0;i

这是附加的java类。在这个java类中,调用了更多的函数

您的方法存在许多问题:

  • 可能导致此问题的主要原因是,所写入的文件始终具有相同的名称,因此您将获得并发写入以及由此可能发生的各种不愉快情况。Mule是一个高度并发的环境:您需要相应地编写代码
  • 这个转换器做的太多了:一个转换器应该只转换数据
  • 每次都会加载属性,而不是从Spring配置注入属性
  • 自定义基于Java的文件编写代码,而不是使用
    文件:出站端点
  • interchangablepriority
    的调用可能应该在组件中完成。如果是线程安全的,那么只创建一个带有Springbean的对象,并在组件中使用它
  • 很难理解超时的意图
  • 化妆品:
    ProvinceName
    =>
    ProvinceName
    (Java编码标准)

嗯,这是第一次。您确定队列中等待的两条消息不同吗?或者是否存在
自定义转换器保持状态并将第一条消息重放两次的风险?是的……我确信这两条消息是不同的。我认为自定义转换将消息重放两次。如果我将从队列中收到的消息延迟几秒钟,这是否是一个解决方案?如果是,那么请建议我如何做。不,引入延迟不是解决方案。你能分享自定义转换器的代码吗?我附加了有问题的自定义类本身。请检查问题中的内容。实际发生的是,而不是每个soap消息的整个流程,wmq获取soap消息的时间比流执行所花费的时间要短。因此…有没有机会修改dis代码只是为了得到解决方案,因为我无法更改java代码。什么是异步或同步流。这东西能帮上忙吗??有什么建议吗??