0

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?

Capitan Planet
  • 155
  • 3
  • 14
  • 1
    Can you share the data adapter class? Are you sure exceptions are actually caught or there is ever a delivery error - Did you try logging them first? – OneCricketeer Sep 07 '22 at 14:01
  • He is eating all exceptions inside the `catch`. What a horrible, unhelpful way of error handling. – Uwe Keim Sep 07 '22 at 14:04
  • 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. "exception inside the catch" is jut for debugging purposes. IDK, Maybe I should put this operation on another thread? – Capitan Planet Sep 08 '22 at 15:54

0 Answers0