Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
timeout-minutes: 5
outputs:
code: ${{ github.event_name != 'pull_request' && 'true' || steps.filter.outputs.code }}
docs: ${{ github.event_name != 'pull_request' && 'true' || steps.filter.outputs.docs }}
steps:
- name: Filter changed paths
id: filter
Expand Down Expand Up @@ -73,6 +74,46 @@ jobs:
- 'nuget.config'
- '.editorconfig'
- '.gitattributes'
docs:
- 'README.md'
- 'docs/docs/**'
- 'src/**'
- 'tests/Dekaf.DocTests/**'
- 'Directory.Build.props'
- 'Directory.Build.targets'
- 'Directory.Packages.props'
Comment on lines +77 to +84

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run the docs gate when its workflow changes

The inspected doc-snippets job is controlled by this docs output, but .github/workflows/ci.yml is absent from the allowlist. Consequently, a PR that changes only the job's command or setup marks doc-snippets as skipped; the separate code filter runs the full solution, which does not include Dekaf.DocTests, and ci-passed explicitly accepts skipped jobs. Include this workflow among the docs inputs so changes to the gate itself are exercised.

Useful? React with 👍 / 👎.

- '.github/workflows/ci.yml'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run snippet checks after SDK selection changes

When a PR adds or changes only global.json, the code filter runs but this docs filter remains false. The full-solution build does not include Dekaf.DocTests, and ci-passed accepts the skipped snippet job, so an SDK/compiler change can break this new project without being detected until a later documentation or source change. Include global.json in this allowlist.

Useful? React with 👍 / 👎.


doc-snippets:
name: Documentation Snippets
needs: changes
if: needs.changes.outputs.docs == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
dotnet-quality: 'preview'

- name: Cache NuGet packages
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/Directory.Packages.props', '**/Directory.Build.props', '**/Directory.Build.targets') }}
restore-keys: nuget-${{ runner.os }}-

- name: Compile documentation snippets
run: dotnet run --project tests/Dekaf.DocTests --configuration Release --framework net10.0 -- --repository-root .

nuget-audit:
name: NuGet Vulnerability Audit
Expand Down Expand Up @@ -122,7 +163,7 @@ jobs:
if-no-files-found: warn
retention-days: 30

# The ONLY job that compiles the solution. Runs net10.0 unit tests inline and
# The ONLY job that compiles the full solution. Runs net10.0 unit tests inline and
# ships the built test binaries to every downstream test job as one tarball
# (tar preserves the apphost executable bit; single-file upload is fast).
build:
Expand Down Expand Up @@ -785,7 +826,7 @@ jobs:
# release-only jobs skip on PR runs).
ci-passed:
name: CI Passed
needs: [changes, build, unit-net8, leak-gates-debug, integration, eventhubs-integration, aot-smoke, aot-integration-publish, aot-integration-smoke, release-matrix, release-matrix-aot, publish, code-quality, nuget-audit]
needs: [changes, doc-snippets, build, unit-net8, leak-gates-debug, integration, eventhubs-integration, aot-smoke, aot-integration-publish, aot-integration-smoke, release-matrix, release-matrix-aot, publish, code-quality, nuget-audit]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ dotnet add package Dekaf.Extensions.Hosting
```

```csharp
services.AddDekaf(dekaf =>
{
dekaf.AddConsumerService<OrderProcessor, string, Order>(
consumer => consumer
.WithBootstrapServers("localhost:9092")
.WithGroupId("orders-service"),
dlq => dlq.WithRetryTopics(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30))); // optional DLQ + retry tiers
});

public sealed class OrderProcessor : KafkaConsumerService<string, Order>
{
public OrderProcessor(
Expand All @@ -391,15 +400,6 @@ public sealed class OrderProcessor : KafkaConsumerService<string, Order>
await HandleOrderAsync(result.Value, cancellationToken);
}
}

services.AddDekaf(dekaf =>
{
dekaf.AddConsumerService<OrderProcessor, string, Order>(
consumer => consumer
.WithBootstrapServers("localhost:9092")
.WithGroupId("orders-service"),
dlq => dlq.WithRetryTopics(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(30))); // optional DLQ + retry tiers
});
```

Failed messages flow `orders` → `orders-retry-5s` → `orders-retry-30s` → `orders.DLQ`, carrying headers with the source offset and failure details. See the [Hosted Consumer Services](https://thomhurst.github.io/Dekaf/docs/hosted-services) and [Dead Letter Queues](https://thomhurst.github.io/Dekaf/docs/consumer/dead-letter-queues) docs.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/compression.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ using Dekaf;
var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.UseLz4Compression()
.WithLingerMs(5) // Wait up to 5ms to fill batches
.WithLinger(TimeSpan.FromMilliseconds(5)) // Wait up to 5ms to fill batches
.WithBatchSize(65536) // 64KB batches
.BuildAsync();
```
Expand Down
9 changes: 4 additions & 5 deletions docs/docs/configuration/consumer-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ builder.Services.AddDekaf(dekaf =>
dekaf.AddConsumer<string, Order>(
builder.Configuration.GetSection("Kafka:Consumers:Orders"),
consumer => consumer
.WithValueDeserializer(new JsonDeserializer<Order>())
.WithValueDeserializer(new JsonSerializer<Order>())
.SubscribeTo("orders"));
});
```
Expand Down Expand Up @@ -273,8 +273,7 @@ it is the sole reservation. Coordinator responses do not consume this budget. Ob
How long before consumer is considered dead:

```csharp
.WithSessionTimeout(45000) // 45 seconds (default)
.WithSessionTimeout(TimeSpan.FromSeconds(45)) // Same, using TimeSpan
.WithSessionTimeout(TimeSpan.FromSeconds(45)) // Default
```

## Subscription
Expand Down Expand Up @@ -407,8 +406,8 @@ Setting a callback enables TLS for the connection.
Custom deserializers:

```csharp
.WithKeyDeserializer(new JsonDeserializer<OrderKey>())
.WithValueDeserializer(new JsonDeserializer<Order>())
.WithKeyDeserializer(new JsonSerializer<OrderKey>())
.WithValueDeserializer(new JsonSerializer<Order>())
```

## Advanced Settings
Expand Down
20 changes: 10 additions & 10 deletions docs/docs/configuration/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.ForHighThroughput()
.WithAcks(Acks.All) // Override: want reliability too
.WithLingerMs(10) // Override: even more batching
.WithLinger(TimeSpan.FromMilliseconds(10)) // Override: even more batching
.BuildAsync();
```

Expand Down Expand Up @@ -173,6 +173,12 @@ Create your own preset extensions for consistency across your application:
```csharp
using Dekaf;

// Usage
var producer = await Kafka.CreateProducer<string, Order>()
.WithBootstrapServers("localhost:9092")
.ForOrderProcessing()
.BuildAsync();

public static class DekafPresets
{
public static ProducerBuilder<TKey, TValue> ForOrderProcessing<TKey, TValue>(
Expand All @@ -181,7 +187,7 @@ public static class DekafPresets
return builder
.ForReliability()
.UseLz4Compression()
.WithLingerMs(1); // Slight batching for efficiency
.WithLinger(TimeSpan.FromMilliseconds(1)); // Slight batching for efficiency
}

public static ConsumerBuilder<TKey, TValue> ForOrderProcessing<TKey, TValue>(
Expand All @@ -193,12 +199,6 @@ public static class DekafPresets
.ForLowLatency();
}
}

// Usage
var producer = await Kafka.CreateProducer<string, Order>()
.WithBootstrapServers("localhost:9092")
.ForOrderProcessing()
.BuildAsync();
```

## Choosing a Preset
Expand All @@ -224,9 +224,9 @@ using Dekaf;
var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.WithAcks(Acks.All)
.WithLingerMs(2)
.WithLinger(TimeSpan.FromMilliseconds(2))
.WithBatchSize(32768)
.EnableIdempotence()
.WithIdempotence(true)
.UseZstdCompression()
.BuildAsync();
```
Expand Down
14 changes: 7 additions & 7 deletions docs/docs/consumer/consumer-groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ Get notified when partitions are assigned, revoked, lost, or stopped during grac
```csharp
using Dekaf;

var consumer = await Kafka.CreateConsumer<string, string>()
.WithBootstrapServers("localhost:9092")
.WithGroupId("my-group")
.WithRebalanceListener(new MyRebalanceListener())
.WithPartitionStopTimeout(TimeSpan.FromSeconds(30))
.BuildAsync();

public sealed class MyRebalanceListener : IRebalanceListener, IPartitionStopListener
{
public ValueTask OnPartitionsAssignedAsync(
Expand Down Expand Up @@ -123,13 +130,6 @@ public sealed class MyRebalanceListener : IRebalanceListener, IPartitionStopList
return ValueTask.CompletedTask;
}
}

var consumer = await Kafka.CreateConsumer<string, string>()
.WithBootstrapServers("localhost:9092")
.WithGroupId("my-group")
.WithRebalanceListener(new MyRebalanceListener())
.WithPartitionStopTimeout(TimeSpan.FromSeconds(30))
.BuildAsync();
```

Callback semantics:
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/consumer/dead-letter-queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ builder.Services.AddDekaf(dekaf =>
consumer => consumer
.WithBootstrapServers("localhost:9092")
.WithGroupId("orders-service")
.WithValueDeserializer(new JsonDeserializer<Order>()),
.WithValueDeserializer(new JsonSerializer<Order>()),
dlq => dlq
.WithMaxFailures(3));
});
Expand Down
24 changes: 12 additions & 12 deletions docs/docs/consumer/manual-assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ consumer.Partitions.Unassign();
```csharp
using Dekaf;

// Usage: Read messages 100-200 from partition 0
var reader = new PartitionReader();
await reader.ReadPartitionAsync(
"localhost:9092",
"my-topic",
partition: 0,
startOffset: 100,
endOffset: 200,
async msg => Console.WriteLine(msg.Value),
cancellationToken
);

public class PartitionReader
{
public async Task ReadPartitionAsync(
Expand Down Expand Up @@ -202,18 +214,6 @@ public class PartitionReader
}
}
}

// Usage: Read messages 100-200 from partition 0
var reader = new PartitionReader();
await reader.ReadPartitionAsync(
"localhost:9092",
"my-topic",
partition: 0,
startOffset: 100,
endOffset: 200,
async msg => Console.WriteLine(msg.Value),
cancellationToken
);
```

## Complete Example: Multi-Partition Worker
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ builder.Services.AddDekaf(dekaf =>
"orders",
builder.Configuration.GetSection("Kafka:Consumers:Orders"),
consumer => consumer
.WithValueDeserializer(new JsonDeserializer<Order>())
.WithValueDeserializer(new JsonSerializer<Order>())
.SubscribeTo("orders"));
});
```
Expand Down Expand Up @@ -301,7 +301,7 @@ builder.Services.AddDekaf(dekaf =>
dekaf.AddConsumer<string, Order>(
kafka.GetSection("Consumers:Orders"),
consumer => consumer
.WithValueDeserializer(new JsonDeserializer<Order>())
.WithValueDeserializer(new JsonSerializer<Order>())
.SubscribeTo("orders"));

dekaf.AddAdminClient(kafka.GetSection("Admin"));
Expand Down Expand Up @@ -333,7 +333,7 @@ builder.Services.AddDekaf(dekaf =>
GroupId = "orders"
},
consumer => consumer
.WithValueDeserializer(new JsonDeserializer<Order>())
.WithValueDeserializer(new JsonSerializer<Order>())
.SubscribeTo("orders"));

dekaf.AddAdminClient(
Expand Down Expand Up @@ -400,7 +400,7 @@ builder.Services.AddDekaf(dekaf =>
dekaf.AddConsumerService<OrderProcessorService, string, Order>(consumer => consumer
.WithBootstrapServers(kafkaConfig["BootstrapServers"]!)
.WithGroupId(kafkaConfig["GroupId"]!)
.WithValueDeserializer(new JsonDeserializer<Order>()));
.WithValueDeserializer(new JsonSerializer<Order>()));
});

var app = builder.Build();
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/hosted-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ builder.Services.AddDekaf(dekaf =>
dekaf.AddConsumerService<OrderProcessorService, string, Order>(consumer => consumer
.WithBootstrapServers(builder.Configuration["Kafka:BootstrapServers"]!)
.WithGroupId("orders-service")
.WithValueDeserializer(new JsonDeserializer<Order>()));
.WithValueDeserializer(new JsonSerializer<Order>()));
});
```

Expand Down
12 changes: 6 additions & 6 deletions docs/docs/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ var producer = await Kafka.CreateProducer<string, string>()
var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.WithAcks(Acks.Leader) // Don't wait for all replicas
.WithLingerMs(5) // Batch for 5ms
.WithLinger(TimeSpan.FromMilliseconds(5)) // Batch for 5ms
.WithBatchSize(65536) // 64KB batches
.WithCompression(CompressionType.Lz4) // Fast compression
.UseCompression(CompressionType.Lz4) // Fast compression
.BuildAsync();
```

Expand All @@ -157,7 +157,7 @@ var producer = await Kafka.CreateProducer<string, string>()
var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.WithAcks(Acks.Leader)
.WithLingerMs(0) // Send immediately
.WithLinger(TimeSpan.Zero) // Send immediately
.WithBatchSize(16384) // Smaller batches
.BuildAsync();
```
Expand Down Expand Up @@ -255,7 +255,7 @@ using Dekaf;
// LZ4 for balanced performance
var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.WithCompression(CompressionType.Lz4)
.UseCompression(CompressionType.Lz4)
.BuildAsync();
```

Expand Down Expand Up @@ -383,11 +383,11 @@ The default batch settings are conservative. If you can tolerate some latency, b

```csharp
// High latency tolerance, maximize throughput
.WithLingerMs(100)
.WithLinger(TimeSpan.FromMilliseconds(100))
.WithBatchSize(1048576)

// Low latency required
.WithLingerMs(0)
.WithLinger(TimeSpan.Zero)
.WithBatchSize(16384)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/producer/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ using Dekaf;

var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.WithLingerMs(5) // Wait up to 5ms to collect more messages
.WithLinger(TimeSpan.FromMilliseconds(5)) // Wait up to 5ms to collect more messages
.WithBatchSize(65536) // Maximum batch size in bytes
.BuildAsync();
```
Expand Down Expand Up @@ -147,7 +147,7 @@ using Dekaf;

var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.EnableIdempotence()
.WithIdempotence(true)
.BuildAsync();
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/producer/fire-and-forget.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ using Dekaf;
var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.ForHighThroughput() // Preset with good defaults
.WithLingerMs(10) // Allow more time for batching
.WithLinger(TimeSpan.FromMilliseconds(10)) // Allow more time for batching
.WithBatchSize(131072) // Larger batches (128KB)
.UseLz4Compression() // Compress batches
.BuildAsync();
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/producer/partitioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ using Dekaf;
var producer = await Kafka.CreateProducer<string, string>()
.WithBootstrapServers("localhost:9092")
.WithPartitioner(PartitionerType.Sticky)
.WithLingerMs(5)
.WithLinger(TimeSpan.FromMilliseconds(5))
.BuildAsync();

// These will likely batch together in one partition
Expand Down
Loading
Loading