﻿# Learning Transport

<!-- Version variant: core_8; default: [/transports/learning/index.md](/transports/learning/index.md) -->


The Learning Transport simulates queuing infrastructure by storing all message actions in the local file system. All files and directories are relative to the current solution directory.

> [!CAUTION]
> The [Learning Transport](/transports/learning/index.md) and [Learning Persistence](/persistence/learning/index.md) are not for production use. They are designed for short term learning and experimentation purposes. It should also not be used for longer-term development, i.e. the same transport and persistence used in production should be used in development and debug scenarios. Select a production transport and persistence before developing features. Do not use the learning transport or learning persistence to perform any kind of performance analysis.

Added in Version 6.3.


Some recommended use cases are:

 * Learning/Experimenting with NServiceBus features.
 * Building a [spike](https://en.wikipedia.org/wiki/Spike_(software_development)) or [demo](https://simple.wikipedia.org/wiki/Demo_(software)).
 * Reproducing a bug that is not related to a production transport, for example when raising a support case.

[ServiceControl](/servicecontrol/index.md) (and therefore [ServicePulse](/servicepulse/index.md)) are only supported for demonstration purposes through the use of the [Platform Sample package](/platform/platform-sample-package.md).

## Transport at a glance

|Feature                    |   |
|:---                       |---
|Transactions |None, ReceiveOnly, SendsWithAtomicReceive
|Pub/Sub                    |Native
|Timeouts                   |Native
|Large message bodies       |LearningTransport can handle arbitrary message sizes within available resources
|Scale-out             |Competing consumer
|Scripted Deployment        |Not supported
|Installers                 |Not supported, the transport always creates the required folder structure
|Native integration         |Not supported
|Case Sensitive             |Yes
|Aspire integration         |[Yes](/platform/aspire/index.md#configuring-the-transport-learning-transport)

### Publish and subscribe

The learning transport simulates a [multicast transport](/transports/types.md#multicast-enabled-transports), so routing configuration isn't needed to publish events. See the [native publish/subscribe](/nservicebus/messaging/publish-subscribe/index.md#mechanics-native) documentation for further details.

## Usage

<!-- snippet: LearningTransport -->

```cs
endpointConfiguration.UseTransport<LearningTransport>();
```

<!-- endsnippet -->

### Transactions and delivery guarantees

The transport supports the following [Transport Transaction Modes](/transports/transactions.md):

 * Sends atomic with Receive (Default)
 * Receive Only
 * Unreliable (Transactions Disabled)

### Concurrency

By default, the transport runs with concurrency limited to 1. See the [tuning](/nservicebus/operations/tuning.md) for details on how to configure concurrency levels.

> [!NOTE]
> Production transports will run with a higher concurrency setting by default

### Storage Directory

By default, all data is stored in a `.learningtransport` directory. The endpoint will traverse the folder hierarchy upwards to find a `.learningtransport` directory, or create one at the solution root folder if no matching directory is found.

To manually configure the storage location:

<!-- snippet: StorageDirectory -->

```cs
var transport = endpointConfiguration.UseTransport<LearningTransport>();
transport.StorageDirectory("PathToStoreTransportFiles");
```

<!-- endsnippet -->

> [!WARNING]
> When using source control, the storage directory should be excluded and never committed.


### Payload size restriction

To simulate a real transport, the learning transport's serialized message size is limited to 64 kB. To remove this restriction:

<!-- snippet: NoPayloadSizeRestriction -->

```cs
var transport = endpointConfiguration.UseTransport<LearningTransport>();
transport.NoPayloadSizeRestriction();
```

<!-- endsnippet -->


## File System Structure

### Subscription metadata

Native publish-subscribe is simulated by storing subscriber metadata in a `.events` folder at the root of the storage directory. Subscribers will write their address to a file named `{storage directory}\.events\{message type fullname}\{endpointname}.subscription`. Publishers will send copies of each published event to all registered subscribers.

### Message File Types


#### Body File

The serialized contents of a message.

 * Serialization is done using the configured [Serializer](/nservicebus/serialization/index.md).
 * File convention is `[MessageId].body.txt`.


#### Metadata File

A serialized representation of the message metadata.

 * The first line is the path to the Message Body File.
 * The remaining lines are the JSON-serialized headers of the message.
 * File convention is `[MessageId].metadata.txt`.


### Error Directory

When a message fails processing, both its metadata and body files will be moved to the "error" directory. The name of the directory will be derived from [configured error queue address](/nservicebus/recoverability/configure-error-handling.md#configure-the-error-queue-address). The default error queue name, and hence the directory name, is "error".


### Endpoint Structure

Each endpoint will have a corresponding directory under `.learningtransport` with the following structure:


#### Metadata files

Each incoming message will have a corresponding Metadata File at the root of the endpoint directory.


#### .bodies (directory)

Each incoming message will have a corresponding Body in this directory.


#### .delayed (directory)

Used to store messages that have been sent with a [Delayed Delivery](/nservicebus/messaging/delayed-delivery.md). One directory per timestamp (of a second granularity) with the format `yyyyMMddHHmmss`. Each timestamp directory can contain multiple Metadata Files.


#### .pending (directory)

A transaction directory that is used to mark a message as being processed. Also prevents duplicate processing.

#### .committed (directory)

Used to temporarily store outgoing messages that are sent during the processing of another message.
