File Share DataBus

Project Hosting | Nuget: NServiceBus (Version: 6.x)

The FileShare DataBus allows large properties to be transferred via a windows file share

Also leverages both serialization and headers to provide its functionality.

Usage

Edit
var dataBus = endpointConfiguration.UseDataBus<FileShareDataBus>();
dataBus.BasePath(databusPath);

Cleanup Strategy

FileShareDataBus does not remove physical attachments once the message has been processed.

The business requirements can indicate how a message and its corresponding file should be processed and when the files can safely be removed. One strategy to deal with these attachments is to set up a cleanup policy which removes any attachments after a certain number of days has passed based on business Service Level Agreements.

The file location used by the DataBus is set during configuration time.

Edit
var dataBus = endpointConfiguration.UseDataBus<FileShareDataBus>();
dataBus.BasePath(@"\\share\databus_attachments\");

This same location should be used when performing the cleanup.

So for example this path can be used in a Handler for a message containing DataBus properties.

Edit
public class Handler :
    IHandleMessages<MessageWithLargePayload>,
    IHandleMessages<RemoveDatabusAttachment>
{

    public Task Handle(MessageWithLargePayload message, IMessageHandlerContext context)
    {
        var filePath = Path.Combine(@"\\share\databus_attachments\", message.LargeBlob.Key);
        var removeAttachment = new RemoveDatabusAttachment
        {
            FilePath = filePath
        };
        var options = new SendOptions();
        options.RouteToThisEndpoint();
        options.DelayDeliveryWith(TimeSpan.FromDays(30));
        return context.Send(removeAttachment, options);
    }

    public Task Handle(RemoveDatabusAttachment message, IMessageHandlerContext context)
    {
        var filePath = message.FilePath;
        // Code to clean up
        return Task.CompletedTask;
    }
}

Samples


Last modified