【发布时间】: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