﻿# Customizing the data bus

<!-- Version variant: core_9; default: [/nservicebus/messaging/claimcheck/custom.md](/nservicebus/messaging/claimcheck/custom.md) -->


Endpoints support sending and receiving large chunks of data via the [data bus](index.md).

It is possible to create a custom data bus implementation. This is done by using the [Features](/nservicebus/pipeline/features.md) extension.

> [!WARNING]
> As of NServiceBus 9.2, the `DataBus` feature is available as a [dedicated NuGet package](https://www.nuget.org/packages/NServiceBus.ClaimCheck/). The API documented on this page will continue to work for NServiceBus Version 9 but it will hint about its upcoming obsoletion with the following warning: *The DataBus feature is released as a dedicated 'NServiceBus.ClaimCheck' package.*.
> The new documentation is [here](/nservicebus/messaging/claimcheck/index.md).


## Implement the `IDataBus` interface

This new class will provide the custom implementations for the `Get` and `Put` methods for the data bus.

<!-- snippet: CustomDataBus -->

```cs
class CustomDataBus :
    IDataBus
{
    public Task<Stream> Get(string key, CancellationToken cancellationToken)
    {
        Stream stream = File.OpenRead("blob.dat");
        return Task.FromResult(stream);
    }

    public async Task<string> Put(Stream stream, TimeSpan timeToBeReceived, CancellationToken cancellationToken)
    {
        await using var destination = File.OpenWrite("blob.dat");
        await stream.CopyToAsync(destination, 81920, cancellationToken);
        return "the-key-of-the-stored-file-such-as-the-full-path";
    }

    public Task Start(CancellationToken cancellationToken)
    {
        return Task.CompletedTask;
    }
}
```

<!-- endsnippet -->

This new implementation needs to be registered as a new feature.

## Define a feature

Define a [new feature](/nservicebus/pipeline/features.md) that registers the custom data bus implementation class.

<!-- snippet: CustomDataBusFeature -->

```cs
class CustomDatabusFeature : Feature
{
    public CustomDatabusFeature()
        => DependsOn<DataBus>();

    protected override void Setup(FeatureConfigurationContext context)
        => context.Services.AddSingleton<IDataBus, CustomDataBus>();
}
```

<!-- endsnippet -->

## Define a DataBusDefinition

Define a new class that inherits from the `DataBusDefinition` class.

<!-- snippet: CustomDataBusDefinition -->

```cs
class CustomDatabusDefinition : DataBusDefinition
{
    protected override Type ProvidedByFeature()
        => typeof(CustomDatabusFeature);
}
```

<!-- endsnippet -->

## Configure the endpoint

Configure the endpoint to use the custom data bus implementation instead of the default data bus:

<!-- snippet: PluginCustomDataBus -->

```cs
endpointConfiguration.UseDataBus(svc => new CustomDataBus(), new SystemJsonDataBusSerializer());
```

<!-- endsnippet -->
