Custom Data Bus Implementation

Component: NServiceBus
NuGet Package NServiceBus (5.x)
Standard support for version 5.x of NServiceBus has expired. For more information see our Support Policy.

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

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

class CustomDataBus :
    IDataBus
{
    public Stream Get(string key)
    {
        return File.OpenRead("blob.dat");
    }

    public string Put(Stream stream, TimeSpan timeToBeReceived)
    {
        using (var destination = File.OpenWrite("blob.dat"))
        {
            stream.CopyTo(destination);
        }
        return "the-key-of-the-stored-file-such-as-the-full-path";
    }

    public void Start()
    {
    }
}

To configure the endpoint to use the custom data bus implementation it is enough to register it at endpoint configuration time, as shown:

busConfiguration.UseDataBus(typeof(CustomDataBus));

Samples


Last modified