Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation with changes from v3 #477

Merged
merged 1 commit into from
Nov 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ Inside the _Producer_ project directory, run the following commands to install t
dotnet add package KafkaFlow
dotnet add package KafkaFlow.Microsoft.DependencyInjection
dotnet add package KafkaFlow.LogHandler.Console
dotnet add package KafkaFlow.TypedHandler
dotnet add package KafkaFlow.Serializer
dotnet add package KafkaFlow.Serializer.JsonCore
dotnet add package Microsoft.Extensions.DependencyInjection
```
Expand Down Expand Up @@ -153,8 +151,6 @@ Inside the _Consumer_ project directory, run the following commands to install t
dotnet add package KafkaFlow
dotnet add package KafkaFlow.Microsoft.DependencyInjection
dotnet add package KafkaFlow.LogHandler.Console
dotnet add package KafkaFlow.TypedHandler
dotnet add package KafkaFlow.Serializer
dotnet add package KafkaFlow.Serializer.JsonCore
dotnet add package Microsoft.Extensions.DependencyInjection
```
Expand All @@ -165,7 +161,6 @@ Create a new class file named _HelloMessageHandler.cs_ and add the following exa

```csharp
using KafkaFlow;
using KafkaFlow.TypedHandler;
using Producer;

namespace Consumer;
Expand Down Expand Up @@ -193,7 +188,6 @@ Replace the content of the _Program.cs_ with the following example.
using KafkaFlow;
using KafkaFlow.Serializer;
using Microsoft.Extensions.DependencyInjection;
using KafkaFlow.TypedHandler;
using Consumer;

const string topicName = "sample-topic";
Expand All @@ -210,7 +204,7 @@ services.AddKafka(kafka => kafka
.WithBufferSize(100)
.WithWorkersCount(10)
.AddMiddlewares(middlewares => middlewares
.AddSerializer<JsonCoreSerializer>()
.AddDeserializer<JsonCoreDeserializer>()
.AddTypedHandlers(h => h.AddHandler<HelloMessageHandler>())
)
)
Expand Down
2 changes: 1 addition & 1 deletion website/docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void ConfigureServices(IServiceCollection services)
.WithBufferSize(100)
.WithWorkersCount(10)
.AddMiddlewares(middlewares => middlewares
.AddSerializer<JsonCoreSerializer>()
.AddDeserializer<JsonCoreDeserializer>()
.AddTypedHandlers(handlers => handlers
.AddHandler<SampleMessageHandler>())
)
Expand Down
55 changes: 25 additions & 30 deletions website/docs/getting-started/packages.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions website/docs/guides/consumers/add-consumers.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Using the `Topic()` or `Topics()` methods, the consumer will trigger the automat
using KafkaFlow;
using KafkaFlow.Serializer;
using Microsoft.Extensions.DependencyInjection;
using KafkaFlow.TypedHandler;

services.AddKafka(kafka => kafka
.AddCluster(cluster => cluster
Expand All @@ -63,7 +62,6 @@ The client application can specify the topic partitions manually using the `Manu
using KafkaFlow;
using KafkaFlow.Serializer;
using Microsoft.Extensions.DependencyInjection;
using KafkaFlow.TypedHandler;

services.AddKafka(kafka => kafka
.AddCluster(cluster => cluster
Expand Down
14 changes: 4 additions & 10 deletions website/docs/guides/middlewares/batch-consume-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ The Batch Consume Middleware is used to accumulate a number of messages or wait

## How to use it

Install the [KafkaFlow.BatchConsume](https://www.nuget.org/packages/KafkaFlow.BatchConsume) package.
On the configuration, use the `AddBatching` extension method to add the middleware to your consumer middlewares.

```bash
dotnet add package KafkaFlow.BatchConsume
```

On the configuration, use the `BatchConsume` extension method to add the middleware to your consumer middlewares.

The `BatchConsume` method has two arguments:
The `AddBatching` method has two arguments:
- The first one must define the maximum batch size.
- The second one defines the `TimeSpan` that the Middleware waits for new messages to be part of the batch.

Expand All @@ -33,7 +27,7 @@ services.AddKafka(kafka => kafka
.AddMiddlewares(
middlewares => middlewares
...
.BatchConsume(100, TimeSpan.FromSeconds(10)) // Configuration of the BatchConsumeMiddleware
.AddBatching(100, TimeSpan.FromSeconds(10)) // Configuration of the BatchConsumeMiddleware
.Add<HandlingMiddleware>() // Middleware to process the batch
)
)
Expand All @@ -48,7 +42,7 @@ When using the `Batch Consume` middleware, the `IServiceScopeFactory` should be
:::

```csharp
using KafkaFlow.BatchConsume;
using KafkaFlow;

internal class HandlingMiddleware : IMessageMiddleware
{
Expand Down
6 changes: 3 additions & 3 deletions website/docs/guides/middlewares/compressor-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ If you want to build your own way of compress and decompress messages, you can f

## Add a Compressor Middleware

Install the [KafkaFlow.Compressor](https://www.nuget.org/packages/KafkaFlow.Compressor/) package and add the `AddCompressor` extension method to your producer/consumer middlewares to use it.
Add the `AddCompressor`/`AddDecompressor` extension method to your producer/consumer middlewares to use it.

The method receives a class that implements the `IMessageCompressor` interface as a generic argument. This class will be used in the compress/decompress process.
The method receives a class that implements the `ICompressor`/`IDecompressor` interface as a generic argument. This class will be used in the compress/decompress process.

A class instance can be provided as an argument through a factory method too.

Install the [KafkaFlow.Compressor.Gzip](https://www.nuget.org/packages/KafkaFlow.Compressor.Gzip/) package to use the `GzipMessageCompressor` that uses the GZIP algorithm.
Install the [KafkaFlow.Compressor.Gzip](https://www.nuget.org/packages/KafkaFlow.Compressor.Gzip/) package to use the `GzipMessageCompressor`/`GzipMessageDecompressor` that uses the GZIP algorithm.

```csharp
public class Startup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Configuring Consumer Throttling is straightforward with the fluent interface pro
.AddAction(a => a.AboveThreshold(10).ApplyDelay(100))
.AddAction(a => a.AboveThreshold(100).ApplyDelay(1_000))
.AddAction(a => a.AboveThreshold(1_000).ApplyDelay(10_000)))
.AddSerializer<JsonCoreSerializer>()
.AddDeserializer<JsonCoreDeserializer>()
)
)
```
Expand Down
18 changes: 6 additions & 12 deletions website/docs/guides/middlewares/serializer-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ You can use one of the following common serializers or build your own:

## How to use it

Install the [KafkaFlow.Serializer](https://www.nuget.org/packages/KafkaFlow.Serializer) package.
On the configuration, add the `AddSerializer`/`AddDeserializer` extension method to your producer/consumer middlewares to use it.

```bash
dotnet add package KafkaFlow.Serializer
```

On the configuration, add the `AddSerializer` extension method to your producer/consumer middlewares to use it.

The `AddSerializer` method has two arguments:
- The first one must implement the `IMessageSerializer` interface.
The `AddSerializer`/`AddDeserializer` method has two arguments:
- The first one must implement the `ISerializer`/`IDeserializer` interface.
- The second one is optional and must implement the `IMessageTypeResolver` interface. If the parameter is not provided, then the `DefaultTypeResolver` will be used.
Both classes can be provided as an argument through a factory method too.

:::tip
For topics that have just one message type, use the `AddSingleTypeSerializer` method.
For topics that have just one message type, use the `AddSingleTypeSerializer`/`AddSingleTypeDeserializer` method.
:::tip


Expand Down Expand Up @@ -87,7 +81,7 @@ public class Startup
)
.AddConsumer(
...
.AddMiddlewares(middlewares => middlewares.AddSchemaRegistryAvroSerializer()
.AddMiddlewares(middlewares => middlewares.AddSchemaRegistryAvroDeserializer()
)
)
);
Expand All @@ -108,7 +102,7 @@ You can see a detailed explanation [here](https://docs.confluent.io/platform/cur

A type resolver is needed to instruct the middleware where to find the destination message type in the message metadata when consuming and where to store it when producing.

The framework has the `DefaultTypeResolver` that will be used omitting the second type parameter in the `AddSerializer` method. You can create your own implementation of `IMessageTypeResolver` to allow communication with other frameworks.
The framework has the `DefaultTypeResolver` that will be used omitting the second type parameter in the `AddSerializer`/`AddDeserializer` method. You can create your own implementation of `IMessageTypeResolver` to allow communication with other frameworks.

```csharp
public class SampleMessageTypeResolver : IMessageTypeResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ When using a Schema Registry, the schema is read from it, and the first 5 bytes
#### Without Schema Registry
Using other serializers with no Schema Registry, the `DefaultTypeResolver` is used by default. The `DefaultTypeResolver` uses the header `Message-Type` to identify the message type based on the Type fully qualified name.

It's also possible to write your own `TypeResolver` implementing the `IMessageTypeResolver` interface and using it in the `AddSerializer` method in the consumer/producer middleware.
It's also possible to write your own `TypeResolver` implementing the `IMessageTypeResolver` interface and using it in the `AddSerializer`/`AddDeserializer` method in the consumer/producer middleware.

## Configure Typed Handler

Expand Down
Loading