1
votes

Is there a way to cancel a Mirth Channel destination file writer when no data has been returned. I do not want to create a file each time the channel is run. The channel need to run every 2-5 mins to process any pending records in the queue located in sql server.

I am using a Mirth channel to query a sql server database and output the data as a CSV file. I am using Mirth Connect Server 3.2.0.7628.

Here is my script on the destination transformer. I've tried to skip adding to tmp if result.Size() is not greater then zero. Could not find this use case in the Mirth Connect documentation.

var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://xx.xx.x.xx:1433/<dbname>',<user>,<password>);

var result1 = dbConn.executeCachedQuery("exec [z_stored_procedure] param1");

var i = 0;  
if (result1.size()>0)   
{   logger.debug(result1.size())
    while(result1.next())
    {        
          tmp.row += <row>
           <DataField1>"{result1.getString('DataField1')}"</DataField1>
           <DataField2>"{result1.getString('DataField2')}"</DataField2>                                            
          </row>; 
      } 
}

dbConn.close();

2

2 Answers

1
votes

You can always exclude that destination from processing the message.

For instance if a channel has many destinations and each message only needs to be processed by a single destination, by calling destinationSet.removeAllExcept(connectorName) in the source transformer, only that destination will receive the message. Those destinations will have no data stored and will not show up in the Message Browser. This is an alternative to filtering on each destination and can save processing time and disk space.

1
votes

It should work to put your code in the Destination Filter rather than the Transformer.

After your if statement, add an:

else {
return false;
}

If you have data it will run your transformation and pass it to the Destination. If you don't it will filter the message and do nothing to the Destination.