web stats
Stop & Start Channel based on Certain Conditions - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 07-12-2017, 06:32 AM
mikko mikko is offline
Mirth Newb
Join Date: May 2016
Posts: 10
mikko is on a distinguished road
Default Stop & Start Channel based on Certain Conditions


Can anyone suggest the best way to stop and start a channel based on a condition.

In my case, I need to stop and start a channel if the queue message is > 0. The function will trigger once a message is received. So here's what I've tried:

Here's what I have in the postprocessor of my channel:
var cid = 'channel ID';

if (ChannelUtil.getQueuedCount(cid) > 0) {
     logger.info('Stopping channel "' + ChannelUtil.getChannelName(cid) + '" due to queue count > 0');
     logger.info('start channel func');
Problem with this is that I don't know if channel was actually stopped before it was started again.

I was looking for a delay, wait or pause function. So far I found the java.lang.Thread.sleep() function. But this holds the actual process which mean when the stop function triggers and you set a sleep after it, the channel status will sleep to "Stopping".

Basically, to have an accurate trigger of events, I need to wait for the channels to have a state of "Stopped" before I trigger the start function. I searched for this again and found the "Future" java class. Below are some links about it:


Unfortunately, I am not that familiar on the Java language. Does this Java class need to be compiled just like what is mentioned in this guide: http://www.mirthcorp.com/community/w...Mirth+Connect?

I hope you can help me on this.
Reply With Quote
Old 07-12-2017, 07:58 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
Join Date: Oct 2010
Posts: 7,125
narupley is on a distinguished road

Nope, you don't need to compile anything yourself to use ChannelUtil. You can call get() to wait until the operation finishes:

If you need to have a channel restart itself, then do it inside a separate thread:

new java.lang.Thread({
    run:function() {
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

- How do I foo?
- You just bar.

Last edited by narupley; 07-12-2017 at 08:00 AM.
Reply With Quote
Old 07-12-2017, 08:03 AM
mikko mikko is offline
Mirth Newb
Join Date: May 2016
Posts: 10
mikko is on a distinguished road

Thank you! Looks like you put me on the right track
Reply With Quote

mirth channel, restart, start, stop

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 12:56 AM.

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