Rebus 8 - Rebus.Subscriptions.ISubscriptionStorage, but a primary registration already exists

80 Views Asked by At

I'm trying to upgrade from Rebus 7 to Rebus 8, and got this exception:

System.InvalidOperationException: Attempted to register primary -> Rebus.Subscriptions.ISubscriptionStorage, but a primary registration already exists: primary -> Rebus.Subscriptions.ISubscriptionStorage
   at Rebus.Injection.Injectionist.Register[TService](Func`2 resolverMethod, Boolean isDecorator, String description)
   at Rebus.Injection.Injectionist.Register[TService](Func`2 resolverMethod, String description)
   at Rebus.Config.StandardConfigurer`1.Register(Func`2 factoryMethod, String description)
   at Rebus.Config.PostgreSqlConfigurationExtensions.StoreInPostgres(StandardConfigurer`1 configurer, IPostgresConnectionProvider connectionProvider, String tableName, Boolean isCentralized, Boolean automaticallyCreateTables, String schemaName)
   at Rebus.Config.PostgreSqlConfigurationExtensions.StoreInPostgres(StandardConfigurer`1 configurer, String connectionString, String tableName, Boolean isCentralized, Boolean automaticallyCreateTables, Action`1 additionalConnectionSetup)   

I have my subscriptions saved in posgres DB, and if I comment out the call StandardConfigurer<ISubscriptionStorage>.StoreInPostgres(...) it all works ok, but without subscriptions.

1

There are 1 best solutions below

0
mookid8000 On

The error message means that another subscription storage has already been registered.

This would be case if you were using e.g. Azure Service Bus (which has native support for pub/sub messaging, so the transport registers itself as the subscription manager).

BUT since the error came when upgrading from Rebus 7 to Rebus 8, and the big difference between those two versions is that the in-mem transport from v8 also registers itself as a subscription storage (i.e. it works as a transport that has native support for pub/sub), my guess is that that's why there's already a registration... if that's the case, and you still want to use Postgres for subscriptions, the solution is to configure the in-mem transport like this:

services.AddRebus(
    configure => configure
        .Transport(t => t.UseInMemoryTransport(network, "my-queue", registerSubscriptionStorage: false))
);