In this section, we will learn how to use the Batch Consume Middleware.
The Batch Consume Middleware is used to accumulate a number of messages or wait some time to build a collection of messages and deliver them to the next middleware to be processed, as it was just one message.
On the configuration, use the AddBatching
extension method to add the middleware to your consumer middlewares.
services.AddKafka(kafka => kafka
.AddCluster(cluster => cluster
.WithBrokers(new[] { "localhost:9092" })
.AddConsumer(
consumerBuilder => consumerBuilder
...
.AddMiddlewares(
middlewares => middlewares
...
.AddBatching(100, TimeSpan.FromSeconds(10))
.Add<HandlingMiddleware>()
)
)
)
);
To access the batch from the next middleware, use the GetMessagesBatch
method accessible through the context
argument.
warning
When using the Batch Consume
middleware, the IServiceScopeFactory
should be used to create scopes instead of the IServiceProvider
, as the latter may dispose the scope.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4