Skip to content

Rate-Limiting Channel Throughput from Scheduled Scripts

When a channel must stay below a transaction-count cap (a regulatory limit, an upstream system that throttles after N requests) pair a CRON-driven Scheduled Script with qie.pauseChannel and qie.resumeChannel so the channel pauses when it has reached the cap for the period and resumes again at the start of the next period.

This pattern is only valid in Scheduled Scripts. The channel-control bindings (qie.pauseChannel, qie.resumeChannel, qie.getChannel, qie.getMessageCountByChannel) are not appropriate to call from a mapping, condition, or destination script running inside the channel being controlled.

Pattern

Configure two scheduled scripts on the throttled channel:

  1. Throttle check: runs on a fast CRON (every minute, say). Queries the period's message count; pauses the channel if it has reached the cap.
  2. Period reset: runs at the start of each new period (e.g. midnight). Resumes the channel.

On the period-reset script's Channel Scheduled Script Dialog, enable Run script while channel is paused. Otherwise the scheduler skips the run while the channel is paused and the channel never resumes.

Throttle-check script

Runs every minute (CRON: 0 * * * * ?). Counts messages received since the start of the day and pauses if at or over the cap.

var DAILY_LIMIT = 10000;

var now = qie.parseDate(qie.formatDate('yyyy-MM-dd HH:mm:ss'), 'yyyy-MM-dd HH:mm:ss');
var startOfDay = qie.parseDate(qie.formatDate('yyyy-MM-dd') + ' 00:00:00', 'yyyy-MM-dd HH:mm:ss');

var counts = qie.getMessageCountByChannel(null, null, channelId, startOfDay, now);
var receivedToday = parseInt(counts.getNode('/receivedCount'));

if (receivedToday >= DAILY_LIMIT) {
    qie.pauseChannel(qie.getChannel(channelId));
}

channelId is bound automatically in scheduled scripts.

Period-reset script

Runs at midnight (CRON: 0 0 0 * * ?). Resumes the channel for the new day.

qie.resumeChannel(qie.getChannel(channelId));

Source-type caveat

pauseChannel stops a polling source (File, FTP / SFTP, Network Share, Database, Custom Script with polling) from picking up new files or rows, so it is a true rate-limit of receipt.

For socket-based push sources (HL7 MLLP, HTTP Listener, DICOM Listener, ASTM), inbound connections continue to be accepted and messages enter the inbound queue while the channel is paused. Only processing is paused. If the connection rate must be capped at the network level for push sources, use the Management API to fully stop and start the channel from an external scheduler, or place an upstream rate-limiter in front of QIE.