Search code examples
c#asp.net-corenservicebus

how to configure in NServicebus the folder for the learning transport (NService bus 8)


I got this configuration for my NServiceBus:

builder.Host.UseNServiceBus(ctx =>
{
    var endpointConfiguration = new EndpointConfiguration("my.orders");
    var transport = endpointConfiguration.UseTransport(new LearningTransport());
    
    transport.RouteToEndpoint(
        assembly: typeof(CreateOrderMessage).Assembly,
        destination: "my.orders");

    endpointConfiguration.UseSerialization<SystemJsonSerializer>();
    
    var conventions = endpointConfiguration.Conventions();
    conventions.DefiningMessagesAs(type =>
        typeof(IDTestMessage).IsAssignableFrom(type)
    );

    return endpointConfiguration;
});

This places the learning transport files at the root of my solution. And when running inside my docker causes a nasty crash (works fine in local). So I want to specify the folder to use for the learning transport files.

According to the documentation here https://docs.particular.net/transports/learning/ I have tried to updata my code like this:

var endpointConfiguration = new EndpointConfiguration("my.orders");
var transport = endpointConfiguration.UseTransport(new LearningTransport());
transport.StorageDirectory("PathToStoreTransportFiles");
transport.RouteToEndpoint(
    assembly: typeof(CreateOrderMessage).Assembly,
    destination: "my.orders");

And I get this error:

RoutingSettings' does not contain a definition for 'StorageDirectory'

Maybe in the 8 version of the NServicebus library the configuration is done differently? Or maybe I need to install an additional nugget? How do i solve this?


Solution

  • With the new v8 approach, where you create an instance of LearningTransport yourself, you need to set the StorageDirectory property on the instance you create.

    Here's an example:

    var learningTransport = new LearningTransport
    {
        StorageDirectory = "PathToStoreTransportFiles"
    };
    
    var transport = endpointConfiguration.UseTransport(learningTransport);
    

    With that change in place, it might also make sense for you to change the transport local variable to be named routing.

    var learningTransport = new LearningTransport
    {
        StorageDirectory = "PathToStoreTransportFiles"
    };
    
    var routing = endpointConfiguration.UseTransport(learningTransport);
    
    routing.RouteToEndpoint(
        assembly: typeof(CreateOrderMessage).Assembly,
        destination: "my.orders");