2

I have two endpoints.

Endpoint 1:

  • HandlerForMessage X
  • HandlerForMessage Y
  • HandlerForMessage Z

Web endpoint: - No handlers at this time, just sends commands to the bus.

The following happens:

  1. Web -> Send< MessageX >(..);
  2. Endpoint 1: Receive MessageX
  3. Endpoint 1: Handle MessageX and in Handler Bus.Send< MessageY >() and Bus.Send< MessageZ >()
  4. Endpoint 1: Receive MessageY, handle it (this takes 20 seconds)
  5. Endpoint 1: 20 seconds later, after handling MessageY, receive MessageZ and handle it.

Since MessageY, MessageZ have different Handlers can't this be done simultaniously?

Creating another endpoint or moving it to an other endpoint is not an option. I just want it to be multithreaded when it comes to different types of messages (and handlers). I don't see why this is not the default behavior.

How do I configure nservicebus to handle multiple messages at the same time from a different type (with different handler)?

NServiceBus 4.6.5 (or if I need to upgrade to 5, fine I don't mind. Just want to have it multithreaded). Transport: SqlServer and for another project Windows Azure Service Bus

MrH40XX
  • 35
  • 1
  • 9

2 Answers2

3

Unless it has changed since I started using NServiceBus, the "unlicenced" version only runs 1 worker thread so it only processes 1 message at a time.

You can alter this in the config by altering the NumberOfWorkerThreads value on the transport, however you need a valid licence in order to increase the number above 1.

<MsmqTransportConfig MaxRetries="0" NumberOfWorkerThreads="1" />

In NServiceBus v4, you need to configure the MaximumConcurrencyLevel value on the TransportConfig:

<TransportConfig MaximumConcurrencyLevel="5" 
                 MaxRetries="2" 
                 MaximumMessageThroughputPerSecond="0"/>

see Failure handling & throttling

Trevor Pilley
  • 16,156
  • 5
  • 44
  • 60
  • We have the licenses and those are loaded correctly (displayed in the cmd window). We are not using MSMQ but SqlServer (and for another project) Azure Service Bus transports. How to configure this in code? – MrH40XX Dec 24 '14 at 09:09
  • That seems to work but it's not exactly what I want. I would like to do this from codebehind;; BusConfiguration config; config.GetSettings().Set(new TransportConfig() { MaximumConcurrencyLevel = 5 }); does not seem to work. – MrH40XX Dec 24 '14 at 12:50
0

If I'm getting your scenario correctly, this is a single transaction/ unit of work...

All of the messages are invoked by the web endpoint sending a message to the endpoint, and all the subsequent messages are dispatched from that handler... so even though the endpoint can be multi threaded, they are all serialised in the same transaction, so if i'm not wrong they are are going to be sequential...

If you don't want to run multiple endpoints, take a look at this issue describing running multiple endpoints in the same process: https://github.com/Particular/NServiceBus/issues/1357

Does this help?

Sean Farmar
  • 2,254
  • 13
  • 10