0

My ICommand handler is being called twice!
I am self hosting nservicebus in IIS (and debugging using Cassini).

        Configure.ScaleOut(_ => _.UseSingleBrokerQueue());
        Configure.With()
            .AutofacBuilder(container)
            .InMemorySubscriptionStorage()
            .UseInMemoryTimeoutPersister()                
            .UseTransport<SqlServer>("myconnectionstring")
            .UnicastBus()
            .PurgeOnStartup(true)
            .CreateBus()
            .Start(() => Configure.Instance.ForInstallationOn<Windows>().Install());

Here are the message headers in the SQL server [audit] table right after startup, there are two subscriptions for the same event handler?

I am experiencing the same issue with the ICommand handler in that it is being called twice in response to a bus.Send(new CommandInstance())

{"NServiceBus.MessageId":"2a02a10c-9e97-4bc7-9fe9-a26100912bc5","NServiceBus.CorrelationId":"2a02a10c-9e97-4bc7-9fe9-a26100912bc5","NServiceBus.OriginatingEndpoint":"Aureus.Web","NServiceBus.OriginatingMachine":"ARWEN","NServiceBus.MessageIntent":"Subscribe","NServiceBus.ControlMessage":"True","SubscriptionMessageType":"Aureus.Messages.Invoicing.IBalanceCapturedEvent, Aureus.Messages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","WinIdName":"PALANTIR\\Craig","NServiceBus.Version":"4.0.0","NServiceBus.TimeSent":"2013-10-24 06:48:33:086263 Z","NServiceBus.ConversationId":"fcef12be-9904-4fd3-9807-a26100912bc6","NServiceBus.ProcessingEndpoint":"Aureus.Web","NServiceBus.ProcessingMachine":"ARWEN","NServiceBus.ProcessingStarted":"2013-10-24 06:48:33:419799 Z","NServiceBus.ProcessingEnded":"2013-10-24 06:48:33:425799 Z","NServiceBus.OriginatingAddress":"Aureus.Web"}
{"NServiceBus.MessageId":"3c8d0bdd-4951-44af-aff7-a26100912bc5","NServiceBus.CorrelationId":"3c8d0bdd-4951-44af-aff7-a26100912bc5","NServiceBus.OriginatingEndpoint":"Aureus.Web","NServiceBus.OriginatingMachine":"ARWEN","NServiceBus.MessageIntent":"Subscribe","NServiceBus.ControlMessage":"True","SubscriptionMessageType":"Aureus.Messages.Invoicing.IBalanceCapturedEvent, Aureus.Messages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","WinIdName":"PALANTIR\\Craig","NServiceBus.Version":"4.0.0","NServiceBus.TimeSent":"2013-10-24 06:48:33:176271 Z","NServiceBus.ConversationId":"5c47ca76-b2ea-4108-836e-a26100912be1","NServiceBus.ProcessingEndpoint":"Aureus.Web","NServiceBus.ProcessingMachine":"ARWEN","NServiceBus.ProcessingStarted":"2013-10-24 06:48:33:440801 Z","NServiceBus.ProcessingEnded":"2013-10-24 06:48:33:440801 Z","NServiceBus.OriginatingAddress":"Aureus.Web"}

I have a single command handler for a particular command in the assembly. It's being called twice.

The event is being called twice

/// <summary>
/// The balance captured handler.
/// </summary>
public class BalanceCapturedEvt : IHandleMessages<IBalanceCapturedEvent>
{
     ...
}
Jim
  • 14,952
  • 15
  • 80
  • 167
  • Is the event handler hosted on the same endpoint (self hosted IIS)? – Sean Farmar Oct 24 '13 at 13:35
  • Yes it is hosted in the same process. – Jim Oct 24 '13 at 15:21
  • The command seems to also be triggered more than once, even though it's a completely different interface. – Jim Oct 24 '13 at 15:23
  • I suspect you're getting message twice because the IIS under which you run the application is configured to have two worker procecesses and so the bus is registered/created twice. You can see this if you put a breakpoint on bus creation. – Pasi Savolainen Dec 09 '13 at 22:02
  • The dual subscriptions were happening while debugging in Cassini. The application startup break points were only hit once (I checked that). I think it has something to do with having the publisher and subscribers in the same assembly / app domain. – Jim Dec 10 '13 at 05:18
  • You're right. I got that because we were modifying "app.config" (to change nservicebus/transport connection string) which in this case was web.config and IIS resets app domains when that happens -> got twice into bus creation before blowing up totally. Sorry about the wrong lead. – Pasi Savolainen Dec 10 '13 at 18:33

1 Answers1

1

My conclusion has to be that NServiceBus doesn't work quite as well self hosted. I have not found a remedy for this, and have to conclude that its' not possible.

Jim
  • 14,952
  • 15
  • 80
  • 167