Create Producer in C#

Hello,

I have tried to use your library and produce a message to Kafka in .Net 6. And it has some challenges…
However, the message is received but cannot be interpreted by kafka.

And I dont understand how you point to a avro-format-schema when you do ProduceAsync for example? Is it possible to “attach” an avro-schema generated from a class for example?

Any Avro generated classes should have a schema already embedded within them, so there would be nothing for you to do.

See example here using LogMessage class - Decoupling Systems with Apache Kafka, Schema Registry and Avro | Confluent

Hello, thanks for the reply!

That is nice. I didnt now that. You see those how should receive my Message are telling me that I have not formatted the message correctly.
And below is my function for produce, do you see anything obvious?

public static async Task Send (Logger logger, SMSConfig config, SMSProtocol.Sms protocol)
{
bool result = false;

        try
        {
            var cert = await CertificateHandling.getCerts(config.certificateStoreName, config.certificateStoreLocation, config.certificateFindType, config.certificateSearchString, logger);

            if (cert == null)
            {
                logger.Warn("SMS.Send() :  No cert found..?!");
                return false;
            }

            ProducerConfig producerConfig = new ProducerConfig
            {
                BootstrapServers = config.server,
                ClientId = Dns.GetHostName(),
                MessageTimeoutMs = 30000,
                SecurityProtocol = SecurityProtocol.Ssl,
                EnableSslCertificateVerification = false,
            };

            producerConfig.SslKeyPem = "-----BEGIN PRIVATE KEY-----\n" + Convert.ToBase64String(cert.PrivateKey.ExportPkcs8PrivateKey()) + "\n-----END PRIVATE KEY-----";
            producerConfig.SslCertificatePem = "-----BEGIN CERTIFICATE-----\n" + Convert.ToBase64String(cert.Export(X509ContentType.Cert)) + "\n-----END CERTIFICATE-----";

            List<string> tags = new List<string>();
            tags.Add("SMS");

                using (var producer = new ProducerBuilder<Null, SMSProtocol.Sms>(producerConfig)
                    .Build())
                {
                    try
                    {
                        var t = await producer.ProduceAsync(config.sendMessageTopic, new Message<Null, SMSProtocol.Sms> {  Value = protocol });
                        if (logger.IsDebugEnabled)
                        {
                            string responsedata = JsonConvert.SerializeObject(t);
                        }
                        if (t != null)
                        {
                            result = true;
                        }

                        return result;
                    }
                    catch (Exception e)
                    {
                        logger.Error(e);
                        logger.Error(e.InnerException);
                    }
                    finally
                    {
                        producer.Flush();
                        producer.Dispose();
                    }
                }
        }
        catch (Exception ex)
        {
            logger.Error(ex);
            logger.Error(ex.InnerException);
        }

        return result;
    }

You’re using JSONConvert function. If you want to use Avro, then don’t use JSON functions at all