priyanka.sarkar
priyanka.sarkar

Reputation: 26498

How to trigger a Mule job from CLI (Command Line Interface)?

I have the below flow that will make a REST request on a periodic basis and then store the data into the PostgreSQL database.

<jdbc:postgresql-data-source name="PostgreSQL_Data_Source" user="postgres" password="*******" url="jdbc:postgresql://localhost:5432/TestDB" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source"/>
<jdbc:connector name="PostgreSQL_JDBC_Connector" dataSource-ref="PostgreSQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database">
    <jdbc:query key="InsertRecord" value="INSERT INTO "tblJSON"("StoreHere") VALUES (CAST(#[message.payload] AS json))"/>
</jdbc:connector>

<flow name="RESTServiceScheduling" doc:name="RESTServiceScheduling">

     <!-- Step 1: Generates events at a given interval of time -->
     <quartz:inbound-endpoint jobName="RESTServiceJobSchedule" repeatInterval="0" doc:name="Quartz" responseTimeout="10000" cronExpression="0 0 10 ? * *">
          <quartz:event-generator-job/>
     </quartz:inbound-endpoint>


    <!-- Step 2: This will read the REST service data -->
    <http:rest-service-component httpMethod="GET" serviceUrl="http://localhost:12186/RestServiceImpl.svc/StorageUsage" />

    <!-- Step 3: Transform the HTTP-streamed payload into a java.lang.String  -->   
    <object-to-string-transformer doc:name="Object to String"/>

    <!-- Step 4: Dump into the destination Database --> 
    <jdbc:outbound-endpoint exchange-pattern="one-way" queryKey="InsertRecord" queryTimeout="-1" connector-ref="PostgreSQL_JDBC_Connector" doc:name="Destination"/>

</flow>

This works fine but I need a way from CLI (Command Line Interface) to trigger the job.

How can I do so?

Thanks in advance

Upvotes: 1

Views: 721

Answers (2)

Becca
Becca

Reputation: 1580

I know this is an old question with an accepted answer, but an alternative is to use a file endpoint that deletes the file. Set the file (or its endpoint) to have file age 1 and polling frequency 10 seconds. To trigger the flow, create a file with the right name. I found doing this, though, that Mule would not delete the file until the flow was done. It would then pick up the same file multiple times if the flow took longer than the polling period. To get around that, I have one flow that has just a file inbound endpoint, a logger, and an VM outbound endpoint with a specific path. Use a VM inbound endpoint with the same path as you would use the HTTP inbound endpoint above.

edit: You can then use touch or something similar in your CLI to create the file. I found this question looking for an alternative to the way described above.

Upvotes: 1

David Dossot
David Dossot

Reputation: 33413

Use an HTTP inbound endpoint to trigger the flow and call it with curl from the command line.

Upvotes: 2

Related Questions