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

Invalid operation exception, when trying to auto subscribe to events when using Brokered transports #1837

Closed
indualagarsamy opened this issue Dec 9, 2013 · 8 comments
Labels
Milestone

Comments

@indualagarsamy
Copy link
Contributor

When using brokered transports that offer support for centralized pub/sub like RabbitMQ and ActiveMQ, the EndpointMappings to specify event subscriptions are not needed. However, without it, an InvalidOperation exception was being thrown.

Steps to Repro

  1. Have a pub/sub sample that uses RabbitMQ as transport
  2. Add the appropriate assembly redirects for the correct version of NServiceBus.Core and NServiceBus.Host
  3. Remove the EndpointMessageMappings in the unicast bus section for the subscriber.
  4. Notice the error upon startup:
2013-12-09 10:46:09,043 [23] ERROR NServiceBus.Unicast.UnicastBus [(null)] <(null)> - System.InvalidOperationException: No destination could be found for message type Messages.Events.IGotRadarStatistics. Check the <MessageEndpointMappings>
section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.
   at NServiceBus.Unicast.UnicastBus.Subscribe(Type messageType, Predicate`1 condition) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Unicast\UnicastBus.cs:line 377
   at NServiceBus.Unicast.UnicastBus.Subscribe(Type messageType) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Unicast\UnicastBus.cs:line 328
   at NServiceBus.AutomaticSubscriptions.AutoSubscriber.Start() in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\AutomaticSubscriptions\AutoSubscriber.cs:line 24
   at NServiceBus.Unicast.UnicastBus.<>c__DisplayClass1f.<Start>b__1d() in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Unicast\UnicastBus.cs:line 786 could not be started.

Workaround
Add the message mappings in app.config.

NOTE: This used to work in version 4.2

@indualagarsamy
Copy link
Contributor Author

indualagarsamy added a commit to Particular/BugsRepro that referenced this issue Dec 9, 2013
@indualagarsamy
Copy link
Contributor Author

@andreasohlund @SimonCropp -- thoughts??
Until we fix #1838 or do a proper refactoring moving the for loop in here:
https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.Core/Unicast/UnicastBus.cs#L371-390 to MessageDrivenSubscriptionManager

Proposed Fix
I don't think we can rely on DoNotRequireExplicitRouting in https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.Core/AutomaticSubscriptions/AutoSubscribe.cs#L21
What if AutoSubscribe feature is explicitly disabled?

How about?
Add the following check before https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.Core/Unicast/UnicastBus.cs#L371

if (Feature.IsEnabled<MessageDrivenSubscriptions>() == false)
{
        // We are dealing with a brokered transport wired for auto pub/sub.
        SubscriptionManager.Subscribe(messageType, null);
        return;
}

and add the following check before
https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.Core/Unicast/UnicastBus.cs#L421

if (Feature.IsEnabled<MessageDrivenSubscriptions>() == false)
{
        // We are dealing with a brokered transport wired for auto pub/sub.
        SubscriptionManager.Unsubscribe(messageType, null);
        return;
}

@SimonCropp
Copy link
Contributor

looks good to me.

although can the code be

if (!Feature.IsEnabled<MessageDrivenSubscriptions>())
{
        // We are dealing with a brokered transport wired for auto pub/sub.
        SubscriptionManager.Unsubscribe(messageType, null);
        return;
}

@SimonCropp
Copy link
Contributor

also. if !Feature.IsEnabled<MessageDrivenSubscriptions>() and addresses.Count > 0 should an exception be thrown?

@indualagarsamy
Copy link
Contributor Author

@SimonCropp - I think not. Because for ActiveMQ and RabbitMQ, users don't need to specify any message mappings in the app.config. In which case, address.Count will be zero.

@SimonCropp
Copy link
Contributor

@indualagarsamy agreed. but if someone has put some message mapping in the config, that will be ignored, shouldn't we tell them?

@indualagarsamy
Copy link
Contributor Author

So, if addresses.Count > 0, how about we log a warning, stating:

MessageEndpointMappings for event {0} has been defined in the app.config in the UnicastBusConfig section.
MessageEndpointMappings are not necessary for defining event subscriptions, since you are using a brokered transport which supports pub/sub natively.
MessageEndpointMappings is only needed for specifying commands, i.e. Bus.Send destinations.

@SimonCropp
Copy link
Contributor

sounds good

indualagarsamy pushed a commit that referenced this issue Dec 10, 2013
…pings in app.config. In the next version, we can try and warn the user much earlier, as soon as we detect that we have mappings for events as opposed to at Subscribe and Unsubscribe time.
indualagarsamy added a commit to Particular/NServiceBus.RabbitMQ that referenced this issue Dec 11, 2013
indualagarsamy added a commit to Particular/NServiceBus.RabbitMQ that referenced this issue Dec 12, 2013
indualagarsamy pushed a commit that referenced this issue Dec 12, 2013
… an injectable property on the UnicastBus.
@SimonCropp SimonCropp added the Bug label Feb 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants