Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6726431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:55:36+00:00 2026-05-26T09:55:36+00:00

I have this problem where a system contains nodes (windows services) that push messages

  • 0

I have this problem where a system contains nodes (windows services) that push messages to be processed and others that pull messages and process them.

This has been designed in a way that the push nodes balance the load between queues by maintaining a round-robin list of queues and rotating queues after each send. Therefore message 1 will go to queue 1, message 2 to queue 2 etc. This part has been working great so far.

On the message pull end we designed it such that the messages are retrieved in a similar way – first from queue 1, then from queue 2 etc. In theory, each pull node sits on a different machine and in practice, so far, it only listened on a single queue. But a recent requirement made us have a pull node in a machine that listens to more than one queue: One that typically is extremely busy and filled with millions of messages and one that generally only contains a handful of messages.

The problem we are facing is that the way we architected originally the pull nodes goes from queue to queue until a message is found. If it times out (say after a sec) then it moves on to the next queue.

This doesnt work anymore cause Q1 (filled with millions of messages) will be delayed approximately a second per message since after each pull from Q1 we will ask Q2 for a message (and if it doesnt contain any we will wait for a second).

So it goes like this:

Q1 contains 10 messages and Q2 contains none

  • Pull node asks for a message from Q1
  • Q1 returns message immediately
  • Pull node asks for a message from Q1
  • ———— Waiting for a second ————- (Q2 is empty and request times out)
  • Pull node asks for a message from Q1
  • Q1 returns message immediately
  • Pull node asks for a message from Q1
  • ———— Waiting for a second ————- (Q2 is empty and request times out)

etc.

So this is clearly wrong.

I guess I am looking for the best architectural solution here. Message processing does not need to be as real-time as possible but needs to be robust and no message should ever be lost!

I would like to hear your views on this problem.

Thank in advance
Yannis

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:55:37+00:00Added an answer on May 26, 2026 at 9:55 am

    I ended up creating a set of threads – one for each msmq that needs to be processed. In the constructor I initialize those threads:

    Storages.ForEach(queue =>
            {
                Task task = Task.Factory.StartNew(() =>
                {
                    LoggingManager.LogInfo("Starting a local thread to read in mime messages from queue " + queue.Name, this.GetType());
                    while (true)
                    {
                        WorkItem mime = queue.WaitAndRetrieve();
                        if (mime != null)
                        {
                            _Semaphore.WaitOne();
                            _LocalStorage.Enqueue(mime);
    
                            lock (_locker) Monitor.Pulse(_locker);
    
                            LoggingManager.LogDebug("Adding no. " + _LocalStorage.Count + " item in queue", this.GetType());
                        }
                    }
                });
            });
    
    • The _LocalStorage is a thread-safe Queue implementation (ConcurrentQueue introduced in .NET 4.0)

    • The Semaphore is a counting semaphore to control inserts in the _LocalStorage. The _LocalStorage is basically a buffer of received messages but we dont want it to get too large while processing nodes are busy doing work. The effect could be that we retrieve ALL the msmq messages in that _LocalStorage but are busy processing only 5 of them or so. This is bad both in terms of resilience (if the program terminates unexpectedly we lose all these messages) and also in terms of performance as the memory consumption for holding all these items in memory will be huge. So we need to control how many items we hold in the _LocalStorage buffer queue.

    • We Pulse threads waiting for work (see below) that a new item was added to the queue by doing a simple Monitor.Pulse

    The code that dequeues work items from the queue is as follows:

    lock (_locker)
                if (_LocalStorage.Count == 0) 
                    Monitor.Wait(_locker);
    
            WorkItem result;
            if (_LocalStorage.TryDequeue(out result))
            {
                _Semaphore.Release();
                return result;
            }
    
            return null;
    

    I hope this can help someone to sort out a similar issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem where I open Visual Studio and the internal windows are
I have this problem that my sites uses alot of ajax and when a
I have this problem decomposing a relation schema into a set of schemas that
I have this problem I'm hoping someone knows the answer to. I have an
i have this problem to find a particular xml node l have post this
I have this problem I've been trying to tackle for a while. I have
i have this problem: ms-access could not delete and i found a potential solution
I have this problem in my ASP.NET application where I'm seeing some of my
I have this problem containing some inequations and requirement to minimize a value. After
I have this problem where after a field (say Field3 in table MyTable) is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.