Prem
Prem

Reputation: 21

KafkaFLow - Issue with Type based Producer

I have the following setup as described in the documentation. I am using KafkaFlow version 2.4.0. Please find below source code for the same. But i could not receive any messages.

`services.AddKafka(kafka => kafka
    .AddCluster(cluster => cluster
        .WithBrokers(new[] { "localhost:9092" })
        .AddProducer<KafkaCommentProducer>(
            producer => 
                producer.DefaultTopic("Test")
            )
    )
);`


`public class KafkaCommentProducer: IKafkaCommentProducer
{
    private readonly IMessageProducer<KafkaCommentProducer> _producer;

    public ProductEventsProducer(IMessageProducer<KafkaCommentProducer> producer)
    {
        _producer = producer;
    }

    public Task ProduceAsync(Product product) =>
        _producer
            .ProduceAsync(product.Id.ToString(), product);
}
`

`TestController(IKafkaCommentProducer producer)
var result = await producer.ProduceAsync(message);`

Consumer

.\bin\windows\kafka-console-consumer.bat --topic Test --from-beginning --bootstrap-server localhost:9092

I tried a type-based producer and .Net 6 web application

Upvotes: 2

Views: 381

Answers (1)

Gui Ferreira
Gui Ferreira

Reputation: 4637

The snippet doesn't have the Consumer configuration, however, it looks like the problem is due to a serialization/deserialization mismatch.

You need to use the same serialization protocol for both consumer/producer. You can find here an example of how to do it with Protobuf.

Upvotes: 0

Related Questions