Note that there are some explanatory texts on larger screens.

plurals
  1. POCan NServiceBus publish to subscribers in the same AppDomain?
    primarykey
    data
    text
    <p>I have a simple web site. In my API controller I am capturing a Command and Sending it to a Handler. This works perfectly. In the handler I do some processing, and then Publish an event. The event NEVER gets published. I cannot even begin to describe the list of changes I have done to get this working, all to no avail.</p> <p>About the only thing I can see that is different between my app and any sample is that mine has the publisher and subscriber in the same assembly. At this point in time I don't see the need for having a separate NServiceBus process, although I will likely do that at some point.</p> <h3>Handler</h3> <pre><code>public sealed class PortfoliosHandler : IHandleMessages&lt;CreatePortfolioCommand&gt;, IHandleMessages&lt;PortfolioCreatedEvent&gt; { public void Handle(CreatePortfolioCommand message) { // Processing logic, this executes just fine Bus.Publish(new PortfolioCreatedEvent { Name = portfolio.Name }); } public void Handle(PortfolioCreatedEvent message) { // This NEVER executes } } </code></pre> <h3>Config</h3> <pre><code>&lt;UnicastBusConfig ForwardReceivedMessagesTo="audit"&gt; &lt;MessageEndpointMappings&gt; &lt;add Assembly="Project.Domain" Namespace="Project.Domain.PM.Commands" Endpoint="messagebus" /&gt; &lt;add Assembly="Project.Domain" Namespace="Project.Domain.PM.Events" Endpoint="messagebus" /&gt; &lt;/MessageEndpointMappings&gt; &lt;/UnicastBusConfig&gt; </code></pre> <h3>Config Code</h3> <pre><code>NServiceBus.Configure.Transactions.Enable(); var config = NServiceBus.Configure.With(); config = config .AutofacBuilder(container) .Log4Net(new DebugAppender {Threshold = Level.Warn}) .UseTransport&lt;Msmq&gt;() .PurgeOnStartup(true) .UnicastBus() .LoadMessageHandlers() .RunHandlersUnderIncomingPrincipal(false) .InMemorySubscriptionStorage() .UseInMemoryTimeoutPersister(); var bus = config .CreateBus() .Start(() =&gt; Configure.Instance.ForInstallationOn&lt;NServiceBus.Installation.Environments.Windows&gt;() .Install()); </code></pre> <p>Not only does the event handler never fire, but no event message ever appears in the queues, and no record of it being published ever appears in the logs. It's almost as if I never sent it. Here are the log entries emitted by calling the Publish method above:</p> <pre><code>NServiceBus.Unicast.UnicastBus: 15:52:11,984 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.Transports.Msmq.CorrelationIdMutatorForBackwardsCompatibilityWithV3 NServiceBus.Unicast.UnicastBus: 15:52:11,984 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.Transports.Msmq.CorrelationIdMutatorForBackwardsCompatibilityWithV3 NServiceBus.Unicast.UnicastBus: 15:52:12,240 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.Impersonation.Windows.WindowsIdentityEnricher NServiceBus.Unicast.UnicastBus: 15:52:12,240 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.Impersonation.Windows.WindowsIdentityEnricher NServiceBus.Unicast.UnicastBus: 15:52:12,488 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.Unicast.Monitoring.VersionMutator NServiceBus.Unicast.UnicastBus: 15:52:12,488 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.Unicast.Monitoring.VersionMutator NServiceBus.Unicast.UnicastBus: 15:52:12,743 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.Unicast.Monitoring.SentTimeMutator NServiceBus.Unicast.UnicastBus: 15:52:12,743 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.Unicast.Monitoring.SentTimeMutator NServiceBus.Unicast.UnicastBus: 15:52:12,984 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.Unicast.Monitoring.CausationMutator NServiceBus.Unicast.UnicastBus: 15:52:12,984 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.Unicast.Monitoring.CausationMutator NServiceBus.Unicast.UnicastBus: 15:52:13,228 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.Sagas.OriginatingSagaHeaderMutator NServiceBus.Unicast.UnicastBus: 15:52:13,228 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.Sagas.OriginatingSagaHeaderMutator NServiceBus.Unicast.UnicastBus: 15:52:13,475 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.Sagas.AutoCorrelateSagaOnReplyMutator NServiceBus.Unicast.UnicastBus: 15:52:13,475 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.Sagas.AutoCorrelateSagaOnReplyMutator NServiceBus.Unicast.UnicastBus: 15:52:13,721 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.MessageHeaders.MessageHeaderManager NServiceBus.Unicast.UnicastBus: 15:52:13,721 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.MessageHeaders.MessageHeaderManager NServiceBus.Unicast.UnicastBus: 15:52:13,969 DEBUG UnicastBus:0 - Invoking transport message mutator: NServiceBus.Gateway.HeaderManagement.GatewayHeaderManager NServiceBus.Unicast.UnicastBus: 15:52:13,969 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Invoking transport message mutator: NServiceBus.Gateway.HeaderManagement.GatewayHeaderManager </code></pre> <p>These are the log entries that occur shortly thereafter:</p> <pre><code>NServiceBus.Unicast.UnicastBus: 15:52:58,866 DEBUG UnicastBus:0 - Finished handling message. NServiceBus.Unicast.UnicastBus: 15:52:58,866 [23] DEBUG NServiceBus.Unicast.UnicastBus [(null)] &lt;(null)&gt; - Finished handling message. NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver: 15:53:00,900 DEBUG TimeoutPersisterReceiver:0 - Polling for timeouts at 09/20/2013 15:53:00. NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver: 15:53:00,900 [17] DEBUG NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver [(null)] &lt;(null)&gt; - Polling for timeouts at 09/20/2013 15:53:00. NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver: 15:53:01,152 DEBUG TimeoutPersisterReceiver:0 - Polling next retrieval is at 09/20/2013 15:54:01. NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver: 15:53:01,152 [17] DEBUG NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver [(null)] &lt;(null)&gt; - Polling next retrieval is at 09/20/2013 15:54:01. </code></pre> <p>Please help. I am at my wits end. I ported from MassTransit to NServiceBus specifically because of the separation between Commands, Events, and Messages, but after 4 days of banging my head against this, MassTransit looking mighty good.</p> <p>I'm sure it's something really stupid I'm doing, but I'm a noob to NServicebus. I even bought the book to try and help me, to no avail. I cannot see what I'm doing wrong, and I have tried so many permutations of settings I cannot keep track of them all.</p> <h2>Updated 2013/09/23</h2> <p>A suggested I have:</p> <ul> <li>Split the handler in two: a PortfolioCreatedHandler and a CreatePortfolioHandler.</li> <li>Removed <strong>sealed</strong> from the handler</li> <li>Created my own SubscriptionStorage, wrapping InMemorySubscriptionStorage for debugging purposes</li> </ul> <p>I was already using IEvent to mark my events, and ICommand for my commands. Commands are published by the web controllers, and only the handlers publish events.</p> <p>My TestSubscriptionStorage class is being called for Init and GetSubscriberAddressesForMessage, and <strong>not</strong> for Subscribe and Ubsubscribe, so it looks like the problem is that the events are not being subscribed, which is difficult to reconcile with the logs entries below.</p> <p>Here are the logs mentioning the PortfolioCreatedEvent:</p> <pre><code>NServiceBus.Unicast.Routing.StaticMessageRouter: 09:34:25,886 DEBUG StaticMessageRouter:0 - Routing for message: Project.Domain.PM.Events.PortfolioCreatedEvent set to messagebus@SL-T50009909L NServiceBus.Unicast.Routing.StaticMessageRouter: 09:34:25,886 [1] DEBUG NServiceBus.Unicast.Routing.StaticMessageRouter [(null)] &lt;(null)&gt; - Routing for message: Project.Domain.PM.Events.PortfolioCreatedEvent set to messagebus@SL-T50009909L MessageType: Project.Domain.PM.Events.PortfolioCreatedEvent, Recoverable: True, TimeToBeReceived: Not set MessageType: Project.Domain.PM.Events.PortfolioCreatedEvent, Recoverable: True, TimeToBeReceived: Not set NServiceBus.Unicast.MessageHandlerRegistry: 09:34:25,906 DEBUG MessageHandlerRegistry:0 - Associated 'Project.Domain.PM.Events.PortfolioCreatedEvent' message with 'Project.PM.Handers.PortfolioCreatedHandler' handler NServiceBus.Unicast.MessageHandlerRegistry: 09:34:25,906 [1] DEBUG NServiceBus.Unicast.MessageHandlerRegistry [(null)] &lt;(null)&gt; - Associated 'Project.Domain.PM.Events.PortfolioCreatedEvent' message with 'Project.PM.Handers.PortfolioCreatedHandler' handler NServiceBus.Unicast.MessageHandlerRegistry: 09:34:25,916 DEBUG MessageHandlerRegistry:0 - Associated 'Project.Domain.PM.Commands.CreatePortfolioCommand' message with 'Project.PM.Handers.CreatePortfolioHandler' handler NServiceBus.Unicast.MessageHandlerRegistry: 09:34:25,916 [1] DEBUG NServiceBus.Unicast.MessageHandlerRegistry [(null)] &lt;(null)&gt; - Associated 'Project.Domain.PM.Commands.CreatePortfolioCommand' message with 'Project.PM.Handers.CreatePortfolioHandler' handler NServiceBus.Serializers.XML.XmlMessageSerializer: 09:34:26,120 DEBUG XmlMessageSerializer:0 - Initializing type: Project.Domain.PM.Events.PortfolioCreatedEvent, Project.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null NServiceBus.Serializers.XML.XmlMessageSerializer: 09:34:26,120 [1] DEBUG NServiceBus.Serializers.XML.XmlMessageSerializer [(null)] &lt;(null)&gt; - Initializing type: Project.Domain.PM.Events.PortfolioCreatedEvent, Project.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions.MessageDrivenSubscriptionManager: 09:34:35,445 INFO MessageDrivenSubscriptionManager:0 - Subscribing to Project.Domain.PM.Events.PortfolioCreatedEvent, Project.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null at publisher queue messagebus@SL-T50009909L NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions.MessageDrivenSubscriptionManager: 09:34:35,445 [18] INFO NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions.MessageDrivenSubscriptionManager [(null)] &lt;(null)&gt; - Subscribing to Project.Domain.PM.Events.PortfolioCreatedEvent, Project.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null at publisher queue messagebus@SL-T50009909L NServiceBus.AutomaticSubscriptions.DefaultAutoSubscriptionStrategy: 09:34:35,555 DEBUG DefaultAutoSubscriptionStrategy:0 - Autosubscribed to event Project.Domain.PM.Events.PortfolioCreatedEvent NServiceBus.AutomaticSubscriptions.DefaultAutoSubscriptionStrategy: 09:34:35,555 [18] DEBUG NServiceBus.AutomaticSubscriptions.DefaultAutoSubscriptionStrategy [(null)] &lt;(null)&gt; - Autosubscribed to event Project.Domain.PM.Events.PortfolioCreatedEvent </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload