No announcement yet.

Stop & Start Channel based on Certain Conditions

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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) {'Stopping channel "' + ChannelUtil.getChannelName(cid) + '" due to queue count > 0');
         ChannelUtil.stopChannel(cid);'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:

    I hope you can help me on this.

  • #2
    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() {
    Last edited by narupley; 07-12-2017, 07:00 AM.
    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.


    • #3
      Thank you! Looks like you put me on the right track