【问题标题】:How to make compatible wmq with java code in MULE如何在 MULE 中使 wmq 与 java 代码兼容
【发布时间】:2014-05-30 02:45:35
【问题描述】:

这是我在 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 消息将生成 1 个带有 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;
    }
}

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

【问题讨论】:

  • 嗯,这是第一次。您确定队列中等待的两条消息不同吗?还是custom-transformer 保持状态并重播第一条消息两次的风险?
  • 是的...我确信这两条消息是不同的。我认为 custom-transform 正在重播消息两次。如果我将消息延迟几秒钟从队列中获取,这可以成为一个解决方案吗?如果是,请建议我该怎么做。
  • 不,引入延迟不是解决方案。可以分享自定义转换器的代码吗?
  • 我附加了有问题的自定义类本身。请在问题中查看。
  • 实际发生的情况是,与流执行所需的时间相比,wmq 不是为每个soap 消息获取整个流,而是在更短的时间内获取soap 消息。

标签: mule


【解决方案1】:

你的方法有很多问题:

  • 可能导致该问题的主要原因是写入的文件始终具有相同的名称,因此您将获得并发写入以及可能发生的各种麻烦。 Mule 是一个高度并发的环境:您需要相应地编写代码。
  • 这个转换器做得太多了:转换器应该只转换数据。
  • 每次都会加载属性,而不是从 Spring 配置中注入它们。
  • 基于 Java 的自定义文件编写代码已完成,而不是使用 file:outbound-endpoint
  • InterchangeablePriority 的调用可能应该在组件中完成。如果线程安全,则仅使用 Spring bean 创建此对象并在组件中使用它。
  • 很难理解timeOut 的意图。
  • 化妆品:ProvinceName => provinceName(Java 编码标准)。

【讨论】:

  • 所以...是否有机会修改 dis 代码只是为了获得解决方案,因为我无法更改我的 java 代码。
  • 什么是异步流或同步流。这东西能帮上忙吗??有什么建议吗??
猜你喜欢
  • 1970-01-01
  • 2014-09-03
  • 2023-03-15
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多