Custom DataBus implementation

Component: NServiceBus
NuGet Package NServiceBus (6.x)

Endpoints support sending and receiving large chunks of data via the DataBus.

It is possible to create a custom DataBus implementation by implementing the IDataBus interface, such as in the following minimalistic sample:

class CustomDataBus :
    IDataBus
{
    public Task<Stream> Get(string key)
    {
        Stream stream = File.OpenRead("blob.dat");
        return Task.FromResult(stream);
    }

    public async Task<string> Put(Stream stream, TimeSpan timeToBeReceived)
    {
        using (var destination = File.OpenWrite("blob.dat"))
        {
            await stream.CopyToAsync(destination)
                .ConfigureAwait(false);
        }
        return "the-key-of-the-stored-file-such-as-the-full-path";
    }

    public Task Start()
    {
        return Task.CompletedTask;
    }
}

To configure the endpoint to use the custom DataBus implementation it is enough to register it at endpoint configuration time, such as in the following sample:

endpointConfiguration.UseDataBus(typeof(CustomDataBus));

Last modified