Bluekiri Consumer is a framework for abstracting the business layers from streaming platforms like Kafka, RabittMq or any other related.
- Start creating a new command-line application.
- Install Bluekiri.Consume NuGet package from
- Nuget
- Add the following lines on your configure services block if your are using Kafka:
.ConfigureServices((hostContext, services) =>
{
services.AddConsumerConfiguration<KafkaConsumer, KafkaConsumerOptions>(o =>
{
o.Topics.Add("test-topic");
o.SetProperty("bootstrap.servers", "localhost:9092");
o.SetProperty("group.id", "mygroupId");
...
});
})
To create new handlers you must use the abstract class MessageHander in addition to adding the attribute MessageType to the class, you can follow the next example:
[MessageType("sample-message", typeof(Test))]
public class SampleHandler : MessageHandler
{
public override Task HandleAsync<Test>(Test message)
{
return Task.CompletedTask;
}
}
One of the requirements for everything to work are the headers. Two are necessary: ContentType and MessageType
-
ContentType: It is a string and defines which is the format with which we have introduced the message in the queue (Json, Protobuff, etc...). By default we use "application/json".
-
MessageType: is a Type and defines the type of the message.