web stats
Any ideas on how to monitor queued messages? - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 09-04-2014, 11:39 AM
jimmarks jimmarks is offline
Mirth Newb
Join Date: Apr 2013
Posts: 15
jimmarks is on a distinguished road

Originally Posted by atibbits View Post
Here is what I use to send out alerts for messages stuck in queue on specific channels:

You can change the var qAlarm amount to send the alert for groups of queues. For example, I have 10 in this example and that means that every time 10 new messages get added to the queue an alert is sent out (i.e. 10, 20, 30, etc...).
So, I really liked this concept and Thanks for the code. I took this and modified it for 3.X and made a few changes. The reason for my changes was we use an on-call system and don't monitor emails during the night typically.

I placed the Post processor script into Pre-Processor also, because what ended up happening was the queue was on the incoming thread and that was the only thing we weren't really monitoring. This allowed us to see what is being done because the post process wouldn't happen in our issue.

I also changed the hour monitor to minutes. This allowed us to change the time frames based on time of day a little easier.

Here it is:


// This script executes once when the channel is deployed
// You only have access to the globalMap and globalChannelMap here to persist data

var rightnow = new Date();
var newtime = rightnow - (3 * (1000 * 60 * 60))

globalMap.put(channelId + '_lastalert',newtime);



// Modify the message variable below to pre process data
var lastsent = globalMap.get(channelId + '_lastalert'); //last time an alert was sent
var rightnow = new Date(); //Current Datetime
var hLimit = 0;

if (rightnow.getHours() >= 13)
hLimit = 30; //Number of hours before resending an alert
var emTo = 'TO Address';
var emCC = 'CC Address';
else {

hLimit = 60;
var emTo = 'TO Address';
var emCC = ' ';

var datediff = (rightnow - lastsent) / (1000 * 60); //calculates hours since last alert went out

if (datediff < hLimit) {

return message;

else {

var channelName = ChannelUtil.getDeployedChannelName(channelId);

//I include all these so you can see what's available
var mSent = ChannelUtil.getSentCount(channelId);
var mReceived = ChannelUtil.getReceivedCount(channelId);
var mQueued = ChannelUtil.getQueuedCount(channelId);
var mError = ChannelUtil.getErrorCount(channelId);

var qAlarm = 5;

if (mQueued >= qAlarm) //This checks the limit of queued messages in groups of (qAlarm) 10.

var emFrom = 'FROM ADDRESS'; //This is the "From" address that will appear on your email
var emSubj = 'Queue Alert for Channel (LIVE): ' + channelName; //This is the subject of the email
var emBody = 'Queued messages detected on channel (LIVE) ' + channelName + '.\n';
emBody = emBody + 'Current number of queued messages is ' + mQueued.toString() + '.\n';
emBody = emBody + 'This alert will not be resent for ' + hLimit.toString() + ' minutes.\nPlease do not respond to this email. This address is not monitored.\n';
emBody = emBody + 'Message Sent at ' + rightnow + ' \n';

var smtpConn = SMTPConnectionFactory.createSMTPConnection(); //Opens email connection using email settings in your Mirth Connect Settings.


globalMap.put(channelId + '_lastalert',rightnow);

return message;

Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 07:14 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation