我是使用MuleSoft的新手。我已经下载了Anypoint Studio,并试图创建一个概念验证。我想我很接近,但不是很接近。基本上这是我想要发生的事情的流程:
我想要的是每秒将一条记录写入xsd结构,并为其生成一个新文件。因此,如果数据库中有10条记录,则每次轮询数据库查询时都会生成10个XML文件。
以下是我基于配置XML尝试完成的示例:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
<db:oracle-config name="#######" host="#######" port="####" instance="#######" user="#####" password="######" doc:name="Oracle Configuration"/>
<file:connector name="XML_File" outputPattern="#[payload.planner_id]-#[server.dateTime]-.xml" autoDelete="true" streaming="true" validateConnections="true" doc:name="File" outputAppend="true" recursive="true" writeToDirectory="C:\Users\gm840d\Documents\Projects\IMM\AnypointStudio\FileOutput"/>
<data-mapper:config name="List_Map__To_XML" transformationGraphPath="list_map__to_xml.grf" doc:name="List_Map__To_XML"/>
<data-mapper:config name="List_Map__To_XML_1" transformationGraphPath="list_map__to_xml_1.grf" doc:name="List_Map__To_XML_1"/>
<batch:job name="project_testxmlBatch" >
<batch:input>
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="10" timeUnit="SECONDS"/>
<processor-chain doc:name="Processor Chain">
<db:select config-ref="Ora_IMCT" doc:name="Database">
<db:parameterized-query><![CDATA[select planner, name, work_center
from schema.mytable]]></db:parameterized-query>
</db:select>
</processor-chain>
</poll>
</batch:input>
<batch:process-records>
<batch:step name="Batch_Step" accept-policy="ALL">
<batch:commit doc:name="Batch Commit" size="306">
<data-mapper:transform config-ref="List_Map__To_XML_1" doc:name="List<Map> To XML"/>
<file:outbound-endpoint path="C:\Users\gm840d\Documents\Projects\IMM\AnypointStudio\FileOutput" responseTimeout="10000" encoding="UTF-8" mimeType="text/xml" doc:name="File" connector-ref="XML_File"/>
</batch:commit>
</batch:step>
</batch:process-records>
<batch:on-complete>
<logger message="Total Records exported: #[message.payload.getLoadedRecords()], Processing time: #[message.payload.getElapsedTimeInMillis()]app" level="WARN" doc:name="Logger"/>
</batch:on-complete>
</batch:job>
</mule>
似乎当我运行mule应用程序时,它可以工作到它所有必要记录的位置,但它会在此之后停止。没有生成任何文件或任何文件。每当“poll”每隔几秒运行一次时,这是控制台输出的片段。
*******************************************************************************************************
* - - + APPLICATION + - - * - - + DOMAIN + - - * - - + STATUS + - - *
*******************************************************************************************************
* project_testxml * default * DEPLOYED *
*******************************************************************************************************
INFO 2015-02-27 10:41:23,124 [pool-14-thread-1] com.mulesoft.module.batch.engine.DefaultBatchEngine: Created instance 3a62ec2d-beb0-11e4-adb3-ecf4bb3a71c5 for batch job project_testxmlBatch
INFO 2015-02-27 10:41:23,124 [pool-14-thread-1] com.mulesoft.module.batch.engine.DefaultBatchEngine: Starting input phase
INFO 2015-02-27 10:41:23,124 [pool-14-thread-1] com.mulesoft.module.batch.engine.DefaultBatchEngine: Input phase completed
INFO 2015-02-27 10:41:23,144 [pool-14-thread-1] com.mulesoft.module.batch.engine.queue.BatchQueueLoader: Starting loading phase for instance '3a62ec2d-beb0-11e4-adb3-ecf4bb3a71c5' of job 'project_testxmlBatch'
INFO 2015-02-27 10:41:23,236 [pool-14-thread-1] com.mulesoft.module.batch.engine.queue.BatchQueueLoader: Finished loading phase for instance 3a62ec2d-beb0-11e4-adb3-ecf4bb3a71c5 of job project_testxmlBatch. 306 records were loaded
INFO 2015-02-27 10:41:23,256 [pool-14-thread-1] com.mulesoft.module.batch.engine.DefaultBatchEngine: Started execution of instance '3a62ec2d-beb0-11e4-adb3-ecf4bb3a71c5' of job 'project_testxmlBatch'
INFO 2015-02-27 10:41:32,256 [pool-14-thread-1] com.mulesoft.module.batch.engine.DefaultBatchEngine: Created instance 3fd5e4a4-beb0-11e4-adb3-ecf4bb3a71c5 for batch job project_testxmlBatch
INFO 2015-02-27 10:41:32,256 [pool-14-thread-1] com.mulesoft.module.batch.engine.DefaultBatchEngine: Starting input phase
INFO 2015-02-27 10:41:32,256 [pool-14-thread-1] com.mulesoft.module.batch.engine.DefaultBatchEngine: Input phase completed
INFO 2015-02-27 10:41:32,256 [pool-14-thread-1] com.mulesoft.module.batch.engine.queue.BatchQueueLoader: Starting loading phase for instance '3fd5e4a4-beb0-11e4-adb3-ecf4bb3a71c5' of job 'project_testxmlBatch'
INFO 2015-02-27 10:41:32,327 [pool-14-thread-1] com.mulesoft.module.batch.engine.queue.BatchQueueLoader: Finished loading phase for instance 3fd5e4a4-beb0-11e4-adb3-ecf4bb3a71c5 of job project_testxmlBatch. 306 records were loaded
INFO 2015-02-27 10:41:32,327 [pool-14-thread-1] com.mulesoft.module.batch.engine.DefaultBatchEngine: Started execution of instance '3fd5e4a4-beb0-11e4-adb3-ecf4bb3a71c5' of job 'project_testxmlBatch'
非常感谢任何帮助。一直在寻找谷歌永远找到这样的例子,只是没有到达任何地方。
答案 0 :(得分:1)
在批处理过程记录的批处理步骤中,在数据映射器之前添加集合拆分器,并为每个记录格式实现为xsd定义指定的逻辑,并按指定的方式将其写入文件。
答案 1 :(得分:0)
您的datamapper映射存在问题,它无法转换数据库中提取的数据,因此返回空载荷,这是您的sftp连接器无法创建文件的原因。
此外,如果要为每条记录生成每个文件,则应使用集合拆分器并在轮询连接器中使用水印功能。