﻿# File Share Data Bus


The file-share data bus allows large properties to be transferred over a network file share.

This implementation [leverages both serialization and headers](/nservicebus/messaging/headers.md#file-share-data-bus-headers) to provide its functionality.



## Usage

<!-- snippet: FileShareDataBus -->

```cs
var claimCheck = endpointConfiguration.UseClaimCheck<FileShareClaimCheck, SystemJsonClaimCheckSerializer>();
claimCheck.BasePath(databusPath);
```

<!-- endsnippet -->

## Cleanup strategy

> [!WARNING]
> FileShareDataBus **does not** remove physical attachments once the message has been processed.

The business requirements can specify 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 that removes them after a specified number of days, in line with business Service-Level Agreements.

The file location used by the data bus is set at configuration time.

<!-- snippet: DefineFileLocationForDatabusFiles -->

```cs
var claimCheck = endpointConfiguration.UseClaimCheck<FileShareClaimCheck, SystemJsonClaimCheckSerializer>();
claimCheck.BasePath(@"\\share\databus_attachments\");
```

<!-- endsnippet -->

This same location should be used for cleanup.

For example, this path can be used in a Handler for a message containing data bus properties.

<!-- snippet: HandlerThatCleansUpDatabus -->

```cs
public class Handler :
    NServiceBus.IHandleMessages<MessageWithLargePayload>,
    NServiceBus.IHandleMessages<RemoveDatabusAttachment>
{

    public Task Handle(MessageWithLargePayload message, NServiceBus.IMessageHandlerContext context)
    {
        var filePath = Path.Combine(@"\\share\databus_attachments\", message.LargeBlob.Key);
        var removeAttachment = new RemoveDatabusAttachment
        {
            FilePath = filePath
        };
        var options = new NServiceBus.SendOptions();
        options.RouteToThisEndpoint();
        options.DelayDeliveryWith(TimeSpan.FromDays(30));
        return context.Send(removeAttachment, options);
    }

    public Task Handle(RemoveDatabusAttachment message, NServiceBus.IMessageHandlerContext context)
    {
        var filePath = message.FilePath;
        // Code to clean up
        return Task.CompletedTask;
    }
}
```

<!-- endsnippet -->
