I can't get the error from Kafka. I'm trying to store my results and errors in database (on cmd it is working fine). I Can store message, but never receive an error (for example when Kafka is down). Webforms, .net4.8, confuent.kafka 1.9.2
var conf = new ProducerConfig { BootstrapServers = WebConfigurationManager.AppSettings["KafkaServer"] };
//this one is working fine
PageControl.DataAdapter.StoreMessageHistory("test", 1);
Action<DeliveryReport<Null, string>> handler = r =>
{
if (!r.Error.IsError)
{
//this one is working fine
PageControl.DataAdapter.StoreMessageHistory("msg", 1);
}
else
{
//this is never stored
PageControl.DataAdapter.StoreMessageHistory("error", 0);
}
};
using (var p = new ProducerBuilder<Null, string>(conf).Build())
{
try
{
p.Produce(WebConfigurationManager.AppSettings["MyTopic"], new Message<Null, string> { Value = "message" }, handler);
p.Flush(TimeSpan.FromSeconds(5));
}
catch(Exception e)
{
//this is never stored
PageControl.DataAdapter.StoreMessageHistory("err", 0);
}
}
Edit: I have the answer, but don't have an elegant solution. Problem is that Flush is on 5s delay and default timeout is 3000000ms. If I change timeout below 5000ms everything is starting to work fine.
var conf = new ProducerConfig { BootstrapServers = WebConfigurationManager.AppSettings["KafkaServer"], MessageTimeout = 4000 };
IDK, Maybe I should put this operation on another thread?