Skip to content

Ingesting Empty Files

QIE's standard File source silently discards zero-byte files, the receiver treats them as "nothing to do" and moves on. Some interfaces, though, treat the arrival of a file as the meaningful event regardless of its content (an empty file may signal "processing complete" or "data set ready") and need every file to enter the channel.

Use a Custom Script Receiver instead of the File source. The script walks the watch folder, reads each file (including empty ones), pushes it onto the inbound queue with qie.addInboundMessage, and deletes the source file. Combined with the receiver's Scan Interval or CRON schedule, the effect is the same as a polled File source, minus the empty-file drop.

Script

var watchFolder = new java.io.File('c:\\hl7\\in\\empty');
var files = watchFolder.listFiles();

if (files != null) {
    for (var i = 0; i < files.length; i++) {
        var file = files[i];
        if (file.isDirectory()) continue;

        var name = file.getName();
        qie.debug('Ingesting ' + name + ' (' + file.length() + ' bytes)');

        qie.addInboundMessage(qie.readFile(file), name);
        file.delete();
    }
}

What it does

  1. Lists every entry in the watch folder.
  2. For each non-directory entry, reads its contents into a string (zero-byte files come back as an empty string) and calls qie.addInboundMessage(content, name) to push the message onto the channel's inbound queue.
  3. Deletes the source file after a successful push, so the next poll does not re-ingest it.

Set the receiver's Execution to Continuous with a sensible Scan Interval, or Scheduled with a CRON expression matching the partner's drop cadence.

Caveats

  • Empty messages enter the channel as empty strings. Downstream mapping and condition nodes must tolerate a missing payload. Branch on message.getNode('/').length() (or a similar check) before parsing.
  • The script runs serially per pass. If files arrive faster than the scan interval, the watch folder accumulates; tune the interval accordingly.
  • Hard-coding the folder path locks the channel to one filesystem location. For deployments that move between environments, read the path from a System Variable instead: qie.getVariable('emptyFolderPath').