.NET Deployment Storage
Last Updated: October 23, 2026
Overview
When an app is deployed, Careflow Orchestrator (FlowOps) injects connection details for each storage the image can access as environment variables. Database variables do not say what kind of database they point to, so an app pairs each variable's <label> with the storage metadata from GetDeploymentAsync() to tell a MongoDB storage from a RabbitMQ one.
The .NET sample app implements everything on this page for MongoDB, RabbitMQ and S3 (src/Careflow.Sample/Storage). Examples use Careflow.Sdk 4.0.0.
Environment Variables
<label> is the storage's label exactly as configured in the deployment, including its case, and matches storages[].label in the GetDeploymentAsync() response. A storage labelled mongo_db gives CAREFLOW_DB_mongo_db_ENDPOINT, so use letters, digits and underscores in labels.
| Variable | Source | Value |
|---|---|---|
CAREFLOW_DB_<label>_ENDPOINT | FlowOps (database storage) | Database host. |
CAREFLOW_DB_<label>_PORT | FlowOps (database storage) | Database port, fixed per engine: 5432 PostgreSQL, 3306 MySQL, 27017 MongoDB, 6379 Redis, 5672 RabbitMQ. |
CAREFLOW_DB_<label>_USERNAME | FlowOps (database storage) | Database user. |
CAREFLOW_DB_<label>_PASSWORD | FlowOps (database storage) | Database password. |
CAREFLOW_BLOB_<label>_BUCKET | FlowOps (blob storage) | Bucket name. |
CAREFLOW_BLOB_<label>_PATH | FlowOps (blob storage) | Key prefix inside the bucket, e.g. /. |
CAREFLOW_BLOB_<label>_PROVIDER | FlowOps (blob storage) | Cloud provider of the bucket, in upper case, e.g. AWS. |
CAREFLOW_BLOB_<label>_ACCESS_ID, _ACCESS_KEY, _REGION_NAME | FlowOps (blob storage) | Credentials and region set on the deployment's storage. Empty unless configured. |
CAREFLOW_BLOB_<label>_ENDPOINT | Set manually (optional) | Not injected by FlowOps. Only needed for an S3-compatible endpoint, e.g. local development. |
CAREFLOW_BLK_<label>_PATH | FlowOps (block storage) | Mount path of the volume, e.g. /mnt/<identifier>. |
An image receives variables for every storage it has access to, including shared storages that are listed under another artifact. When matching labels, search the storages of all artifacts, not just your own.
A database's user is also the name of the database created for it (PostgreSQL, MySQL, MongoDB), and the database starts empty. A block storage disk is mounted read-write before the app starts, keeps its data across restarts and redeployments of the same storage, and is not shared between replicas.
config.yaml
Images built on the Careflow Broker base image also receive the same settings in /careflow/config/config.yaml under storage:: database[] (TYPE, USER, PASSWORD, HOST, PORT, NAME), blob[] (PROVIDER, BUCKET, PATH) and block[] (ROUTE). Database entries carry their TYPE, but no entry carries its label, so with several storages of one kind match them by HOST or BUCKET, or use the environment variables.
Identifying Database Storages
Read the deployment once at startup and map each database storage's label to its DatabaseType:
using Careflow.Sdk;
using Careflow.Sdk.Models.Apps;
var deployment = await client.App.GetDeploymentAsync(new GetDeploymentParams());
var databaseTypesByLabel = (deployment.Data?.DeploymentYaml?.Models ?? [])
.SelectMany(model => model.Artifacts ?? [])
.SelectMany(artifact => artifact.Storages ?? [])
.Where(storage => storage.StorageType == StorageType.Database
&& !string.IsNullOrWhiteSpace(storage.Label)
&& storage.DatabaseType is not null)
.GroupBy(storage => storage.Label!)
.ToDictionary(group => group.Key, group => group.First().DatabaseType!.Value);Then find the labels that have a CAREFLOW_DB_<label>_ENDPOINT variable and keep the ones of the type you need:
using System.Collections;
using System.Text.RegularExpressions;
var endpointPattern = new Regex("^CAREFLOW_DB_(?<label>.+)_ENDPOINT$");
var mongoLabels = Environment.GetEnvironmentVariables().Keys
.OfType<string>()
.Select(key => endpointPattern.Match(key))
.Where(match => match.Success)
.Select(match => match.Groups["label"].Value)
.Where(label => databaseTypesByLabel.TryGetValue(label, out var type) && type == DatabaseType.MongoDb)
.ToList();A label with no matching storage, or a type the SDK does not recognise (DatabaseType.Unknown), cannot be classified. The sample app retries GetDeploymentAsync() up to 3 times at startup and disables MongoDB and RabbitMQ if the deployment cannot be loaded.
MongoDB
The database name and auth source are both the username. Escape the credentials:
using MongoDB.Driver;
var host = Environment.GetEnvironmentVariable($"CAREFLOW_DB_{label}_ENDPOINT");
var port = Environment.GetEnvironmentVariable($"CAREFLOW_DB_{label}_PORT");
var user = Environment.GetEnvironmentVariable($"CAREFLOW_DB_{label}_USERNAME");
var password = Environment.GetEnvironmentVariable($"CAREFLOW_DB_{label}_PASSWORD") ?? "";
var portSegment = string.IsNullOrWhiteSpace(port) ? "" : $":{port}";
var connectionString =
$"mongodb://{Uri.EscapeDataString(user)}:{Uri.EscapeDataString(password)}@{host}{portSegment}/{user}?authSource={user}";
var database = new MongoClient(connectionString).GetDatabase(user);Skip the storage if ENDPOINT or USERNAME is missing.
RabbitMQ
Connecting
Port defaults to 5672 when PORT is missing or not a number. USERNAME and PASSWORD are required.
using RabbitMQ.Client;
var factory = new ConnectionFactory
{
HostName = Environment.GetEnvironmentVariable($"CAREFLOW_DB_{label}_ENDPOINT"),
Port = int.TryParse(Environment.GetEnvironmentVariable($"CAREFLOW_DB_{label}_PORT"), out var port) ? port : 5672,
UserName = Environment.GetEnvironmentVariable($"CAREFLOW_DB_{label}_USERNAME"),
Password = Environment.GetEnvironmentVariable($"CAREFLOW_DB_{label}_PASSWORD"),
RequestedConnectionTimeout = TimeSpan.FromSeconds(10)
};
await using var connection = await factory.CreateConnectionAsync($"my-app-{label}");Reuse one connection per label and open a channel per operation.
Publishing with Confirms
Open the channel with publisher confirmations and publish with mandatory: true, so an unconfirmed or unroutable message throws instead of being dropped:
await using var channel = await connection.CreateChannelAsync(new CreateChannelOptions(
publisherConfirmationsEnabled: true,
publisherConfirmationTrackingEnabled: true));
var properties = new BasicProperties
{
MessageId = Guid.NewGuid().ToString("N"),
ContentType = "application/json",
DeliveryMode = DeliveryModes.Persistent
};
await channel.BasicPublishAsync(exchange: "", routingKey: "my-queue", mandatory: true, properties, body);Consuming
Pull messages with BasicGetAsync, then acknowledge them, or reject them back onto the queue:
using System.Text;
await using var channel = await connection.CreateChannelAsync();
var delivery = await channel.BasicGetAsync("my-queue", autoAck: false);
if (delivery is not null)
{
var payload = Encoding.UTF8.GetString(delivery.Body.Span);
await channel.BasicAckAsync(delivery.DeliveryTag, multiple: false);
}The sample app reads up to a requested count, then acks (BasicAckAsync) or requeues (BasicNackAsync with requeue: true) everything up to the last delivery tag.
Error Cases
| Exception | Meaning | Sample app response |
|---|---|---|
BrokerUnreachableException with inner AuthenticationFailureException | Wrong username or password. | 502 |
BrokerUnreachableException | Host or port unreachable. | 503 |
PublishReturnException | No queue matched the exchange and routing key (mandatory: true). | 422 |
PublishException | The broker did not confirm the publish. | 502 |
OperationInterruptedException | The broker closed the channel. ShutdownReason.ReplyCode is 403 (access refused), 404 (queue or exchange not found), 405/406 (resource locked or precondition failed, e.g. redeclaring a queue with different settings). | 403, 404, 409 for 405/406, otherwise 502 |
Queue, exchange and routing key names are limited to 255 bytes.
S3
Blob storages are found by their CAREFLOW_BLOB_<label>_BUCKET variable; they do not need GetDeploymentAsync(). Object keys are the storage path followed by the file name, without a leading /.
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
using Amazon.S3.Model;
var bucket = Environment.GetEnvironmentVariable($"CAREFLOW_BLOB_{label}_BUCKET");
var path = Environment.GetEnvironmentVariable($"CAREFLOW_BLOB_{label}_PATH");
if (string.IsNullOrWhiteSpace(path)) path = "/";
var endpoint = Environment.GetEnvironmentVariable($"CAREFLOW_BLOB_{label}_ENDPOINT");
var region = Environment.GetEnvironmentVariable($"CAREFLOW_BLOB_{label}_REGION_NAME");
var accessId = Environment.GetEnvironmentVariable($"CAREFLOW_BLOB_{label}_ACCESS_ID");
var accessKey = Environment.GetEnvironmentVariable($"CAREFLOW_BLOB_{label}_ACCESS_KEY");
var config = new AmazonS3Config();
if (!string.IsNullOrWhiteSpace(endpoint))
{
config.ServiceURL = endpoint;
config.ForcePathStyle = true;
}
else if (!string.IsNullOrWhiteSpace(region))
{
config.RegionEndpoint = RegionEndpoint.GetBySystemName(region);
}
var s3 = !string.IsNullOrWhiteSpace(accessId) && !string.IsNullOrWhiteSpace(accessKey)
? new AmazonS3Client(new BasicAWSCredentials(accessId, accessKey), config)
: new AmazonS3Client(config);
await s3.PutObjectAsync(new PutObjectRequest
{
BucketName = bucket,
Key = $"{path}{fileName}".TrimStart('/'),
InputStream = content,
ContentType = contentType
});On a Careflow deployment ACCESS_ID and ACCESS_KEY are normally empty and ENDPOINT is not set, so the client uses the default AWS credential chain. That picks up the IAM role FlowOps gives the image, which can list each of its buckets and read, write and delete objects under the storage's PATH; access outside PATH is denied.