Reputation: 584
i did a example Using Mule Studio to read Data from database
i have not any problem or errors but i want to change this program. this program create a lot of files and read one record and save in to in a files and mule program create and create a lot of file until i terminate my program i want to save all records in a file and finish the program (not continue again). i left my xml file
<jdbc:mysql-data-source name="MySQL_Data_Source" user="roor" password="1234" url="jdbc:mysql://localhost:3306/readdata" transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"/>
<jdbc:connector name="Database" dataSource-ref="MySQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<flow name="DBC-PostgreSQL-Mule-ExperimentFlow1" doc:name="DBC-PostgreSQL-Mule-ExperimentFlow1">
<jdbc:inbound-endpoint queryKey="selectplayers" queryTimeout="-1" pollingFrequency="1000" connector-ref="Database" doc:name="Database">
<jdbc:transaction action="NONE"/>
<jdbc:query key="selectplayers" value="Select * From Players;"/>
</jdbc:inbound-endpoint>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<file:outbound-endpoint path="E:\me\Mule\sample\1" responseTimeout="10000" doc:name="File" outputPattern="#[function:dateStamp].txt"/>
</flow>
error after add :
xception in thread "main" org.mule.module.launcher.DeploymentInitException: SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'jdbc:inbound-endpoint'. One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor, "http://www.mulesoft.org/schema/mule/core":response}' is expected.
at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:220)
at org.mule.module.launcher.application.ApplicationWrapper.init(ApplicationWrapper.java:64)
at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:46)
at org.mule.tooling.server.application.ApplicationDeployer.run(ApplicationDeployer.java:56)
at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:88)
Caused by: org.mule.api.config.ConfigurationException: Line 16 in XML document from URL [file:/E:/program/MuleStudio/.mule/apps/dbc-postgresql-mule-experiment/DBC-PostgreSQL-Mule-Experiment.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'jdbc:inbound-endpoint'. One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor, "http://www.mulesoft.org/schema/mule/core":response}' is expected. (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException)
at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52)
at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78)
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:80)
at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:208)
... 4 more
Upvotes: 0
Views: 2205
Reputation: 958
You can use a different inbound endpoint to trigger the jdbc data extraction (Quartz, VM, etc). This way all records are stored in a single mule message and finally in a single file.
<flow name="DBC-PostgreSQL-Mule-ExperimentFlow1" doc:name="DBC-PostgreSQL-Mule-ExperimentFlow1">
<quartz:inbound-endpoint jobName="start" repeatInterval="60000">
<quartz:event-generator-job/>
</quartz:inbound-endpoint>
<jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="selectplayers" queryTimeout="-1" connector-ref="Database" doc:name="Database">
<jdbc:transaction action="NONE"/>
<jdbc:query key="selectplayers" value="Select * From Players;"/>
</jdbc:outbound-endpoint>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<file:outbound-endpoint path="E:\me\Mule\sample\1" responseTimeout="10000" doc:name="File" outputPattern="#[function:dateStamp].txt"/>
</flow>
Regards
Upvotes: 1
Reputation: 33413
This is achieved by using collection aggregation: http://www.mulesoft.org/documentation/display/current/Routing+Message+Processors#RoutingMessageProcessors-CollectionAggregator
In your case you'll have to set a correlation ID and group size that matches your select so Mule will wait for the right number of records to aggregate before writing them to a single file.
Upvotes: 1