SzymonPobiega / NServiceBus.Router

Cross-transport, cross-site and possibly cross-cloud router component for NServiceBus
MIT License
5 stars 10 forks source link

Question about router between MSMQ and SqlServer ('A chain has to have at least one terminator: ForwardPublishContext.') #10

Closed valeriob closed 5 years ago

valeriob commented 5 years ago

Hi, i'm trying to learn how the router works, so i took this sample https://docs.particular.net/samples/router/mixed-transports/ and tring to switch rabbitmq with SqlServer :

    var endpointConfiguration = new EndpointConfiguration("Samples.Router.MixedTransports.Server");

    var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
    transport.ConnectionString("host=localhost");
    transport.UseConventionalRoutingTopology();

    endpointConfiguration.UsePersistence<InMemoryPersistence>();

    var recoverability = endpointConfiguration.Recoverability();
    recoverability.Immediate(immediate => immediate.NumberOfRetries(0));
    recoverability.Delayed(delayed => delayed.NumberOfRetries(0));

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

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

    Console.WriteLine("Press <enter> to exit.");
    Console.ReadLine();

    await endpointInstance.Stop().ConfigureAwait(false);`

The exception is

A chain has to have at least one terminator: ForwardPublishContext.'

image

What am i missing ? Thanks in advance.

SzymonPobiega commented 5 years ago

Hey @valeriob

You're missing the subscription store registration as shown in https://docs.particular.net/samples/router/mixed-transports/#code-walk-through-router: EnableMessageDrivenPublishSubscribe() Unfortunately for now the exception message is really horrible as it does not point you in any direction. I'll be working on making it better soon.

valeriob commented 5 years ago

Hi Szymon, sorry but i pasted the wrong "main", this is the code of the bridge i'm using, EnableMessageDrivenPublishSubscribe() it's present :

 static async Task Main()
 {
    Console.Title = "Samples.Router.MixedTransports.Router";

    var routerConfig = new RouterConfiguration("Samples.Router.MixedTransports.Router");

    var msmqInterface = routerConfig.AddInterface<MsmqTransport>("MSMQ", t => { });
    msmqInterface.EnableMessageDrivenPublishSubscribe(new InMemorySubscriptionStorage());

    var cs = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=NSBTest;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

    var rabbitMQInterface = routerConfig.AddInterface<SqlServerTransport>("RabbitMQ", t =>
    {
        t.ConnectionString(cs);
    });

    var staticRouting = routerConfig.UseStaticRoutingProtocol();
    staticRouting.AddForwardRoute("MSMQ", "RabbitMQ");
    routerConfig.AutoCreateQueues();

    var router = Router.Create(routerConfig);

    await router.Start().ConfigureAwait(false);

    Console.WriteLine("Press <enter> to exit");
    Console.ReadLine();

    await router.Stop().ConfigureAwait(false);
}
SzymonPobiega commented 5 years ago

@valeriob have you tied the trick with EnableMessageDrivenPublishSubscribe above ☝️

valeriob commented 5 years ago

Yes EnableMessageDrivenPublishSubscribe it's already set in msmqInterface

SzymonPobiega commented 5 years ago

@valeriob you need to enable it in both as SQL Server also does not support native pub/sub. They can refer to the same subscription table.

valeriob commented 5 years ago

Thanks @SzymonPobiega that worked ! But now i'm getting this exception, i'm having hard time to understand what's appening : image

SzymonPobiega commented 5 years ago

That looks like attempting to send a message with SQL server transport address to MSMQ