Custom DataBus implementation

Component: NServiceBus | Nuget: NServiceBus (Version: 5.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:

Edit
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 DataBus implementation it is enough to register it at endpoint configuration time, such as in the following sample:

Edit
busConfiguration.UseDataBus(typeof(CustomDataBus));

Last modified