如何使MULE中的Java代码兼容wmq [英] How to make compatible wmq with java code in MULE

查看:94
本文介绍了如何使MULE中的Java代码兼容wmq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Mule中xml的一部分. >

This is the part of my xml in Mule. >

<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记录的文本文件. 问题是,当我运行my子流并将消息逐个放入队列时,一切都很好.但是,如果我直接将2条消息放入队列中,即首先将2条消息放入队列中,然后运行我的流程,则它仅接收第一个SOAP,并且在进行Java转换后,First SOAP的结果在文本文件中打印了2次.

My java code is converting the coming SOAP message from queue into text file. it is designed in such a way that 2 SOAp message will make 1 text file with 2 SOAP records. The issue is, when i am running my mule flow, and putting the message one by one in the queue, everything is fine. But if I directly put 2 message in the queue i.e. first I put 2 message in the queue and then run my flow, it is taking only first SOAP and after java transformation, the result of First SOAP is printing 2 times in the text file.

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类中,将调用其他一些函数.

This is the attached java class. Inside this java class, some more functions are being called.

推荐答案

您的方法有很多问题:

  • 可能导致此问题的主要原因是写入的文件始终具有相同的名称,因此您将获得并发写入以及随之而来的各种麻烦. Mule是高度并发的环境:您需要进行相应的编码.
  • 这个转换器做得太多了:转换器只能转换数据.
  • 每次加载属性,而不是从Spring配置中注入它们.
  • 完成基于Java的自定义文件编写代码,而不使用file:outbound-endpoint.
  • InterchangeablePriority的调用可能应该在组件中完成.如果线程安全,请仅使用Spring bean创建该对象,然后在组件中使用它.
  • 很难理解timeOut的意图.
  • 化妆品:ProvinceName => provinceName(Java编码标准).
  • The main one that probably causes the issue is that the file that is written has always the same name so you'll get concurrent writes and all sorts of nastiness that can happen with that. Mule is a highly concurrent environment: you need to code accordingly.
  • This transformer is doing way too much: a transformer should only transform data.
  • Properties are loaded each time instead of injecting them from the Spring config.
  • Custom Java-based file writing code is done instead of using a file:outbound-endpoint.
  • The call to InterchangeablePriority should probably be done in a component. If thread safe, create this object only one with a Spring bean and use it in a component.
  • It's hard to understand the intent around timeOut.
  • Cosmetics: ProvinceName => provinceName (Java coding standards).

这篇关于如何使MULE中的Java代码兼容wmq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆