Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple concurrent receivers #137

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/MassTransit/ServiceBus.cs
Expand Up @@ -336,6 +336,7 @@ public void Start()
_consumerPool = new ThreadPoolConsumerPool(this, _eventChannel, _receiveTimeout)
{
MaximumConsumerCount = MaximumConsumerThreads,
MaximumReceiverCount = ConcurrentReceiveThreads,
};
_consumerPool.Start();

Expand Down
25 changes: 19 additions & 6 deletions src/MassTransit/Threading/ThreadPoolConsumerPool.cs
Expand Up @@ -36,7 +36,8 @@ public class ThreadPoolConsumerPool :
bool _disposed;
bool _enabled;
ChannelConnection _eventConnection;
int _maximumThreadCount = 25;
int _maximumCounsumerCount = 25;
int _maximumReceiverCount = 1;
int _receiverCount;

public ThreadPoolConsumerPool(IServiceBus bus, UntypedChannel eventChannel, TimeSpan receiveTimeout)
Expand All @@ -48,13 +49,25 @@ public ThreadPoolConsumerPool(IServiceBus bus, UntypedChannel eventChannel, Time

public int MaximumConsumerCount
{
get { return _maximumThreadCount; }
get { return _maximumCounsumerCount; }
set
{
if (value <= 0)
throw new InvalidOperationException("The maximum thread count must be at least one");
throw new InvalidOperationException("The maximum consumer count must be at least one");

_maximumThreadCount = value;
_maximumCounsumerCount = value;
}
}

public int MaximumReceiverCount
{
get { return _maximumReceiverCount; }
set
{
if (value <= 0)
throw new InvalidOperationException("The maximum receiver count must be at least one");

_maximumReceiverCount = value;
}
}

Expand Down Expand Up @@ -162,10 +175,10 @@ void QueueReceiver()

lock (_locker)
{
if (_receiverCount > 0)
if (_receiverCount >= _maximumReceiverCount)
return;

if (_consumerCount >= _maximumThreadCount)
if (_consumerCount >= _maximumCounsumerCount)
return;

// if (_log.IsDebugEnabled)
Expand Down