Subscription not working with NSB 7 and sql transport


(Raj Shelar) #1

I am going through NServiceBus V7 pub-sub sample Tutorial and using the same code except using sql , SQS and Learning transport (for POC). Mainly changes in configuration are done. _Normal command sending functionality working fine for all transports. Also for Learning transport and persistence it subscription working fine.

Here mainly for SQLand SQS transport subscription is NOT working. I am using Nhibernate as persistence for those. My Subscription table remain empty. Below code is for sql transport.

PACKAGES

 <package id="Newtonsoft.Json" version="11.0.1" targetFramework="net462" />
 <package id="NHibernate" version="4.0.4.4000" targetFramework="net462" />
 <package id="NServiceBus" version="7.0.1" targetFramework="net462" />
 <package id="NServiceBus.AmazonSQS" version="4.1.0" targetFramework="net462" />
 <package id="NServiceBus.Newtonsoft.Json" version="2.1.0" targetFramework="net462" />
<package id="NServiceBus.NHibernate" version="8.0.0" targetFramework="net462" />
<package id="NServiceBus.SqlServer" version="4.0.0" targetFramework="net462" />
<package id="System.Data.SqlClient" version="4.4.3" targetFramework="net462" />

CONFIGURATION

var endpointConfiguration = new EndpointConfiguration("Samples.PubSub.Publisher");
        //endpointConfiguration.UsePersistence<LearningPersistence>();
        //endpointConfiguration.UseTransport<LearningTransport>();

        //Persistence
        var persistence = endpointConfiguration.UsePersistence<NHibernatePersistence>();
        var nhConfig = new NHibernate.Cfg.Configuration();
        nhConfig.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
        nhConfig.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.Sql2008ClientDriver");
        nhConfig.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2008Dialect");
        nhConfig.SetProperty(NHibernate.Cfg.Environment.ConnectionString, ConfigurationManager.ConnectionStrings["NSB_AWS.NHibernatePersistence"].ConnectionString);
        nhConfig.SetProperty(NHibernate.Cfg.Environment.DefaultSchema, "nsb");
        persistence.UseConfiguration(nhConfig);
        //Transport
        var transport = endpointConfiguration.UseTransport<SqlServerTransport>()
                        .ConnectionString(ConfigurationManager.ConnectionStrings["NSB_AWS.SqlServerTransport"].ConnectionString);
        transport.DefaultSchema("nsb");

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.EnableInstallers();

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
            .ConfigureAwait(false);
        await Start(endpointInstance)
            .ConfigureAwait(false);
        await endpointInstance.Stop()
            .ConfigureAwait(false);

What I am missing here?


(Raj Shelar) #2

I found the answer, Just register publisher at subscriber end as below
routing.RegisterPublisher(typeof(OrderPlaced), "NSB.Server");


(Tim Bussmann) #3

Good to hear you found the missing routing configuration @eraj2587 and thanks for sharing this on this issue :+1: . While this might be a bit late for you, you might be pleased to hear that the upcoming next minor releases will log an error in case you forgot to register a publisher for an event type. Hopefully, that will help to avoid such issues in the future.