Skip to content

Instantly share code, notes, and snippets.

Created May 17, 2019 06:30
What would you like to do?
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Confluent.Kafka;
namespace Zohan.KafkaDemo
public class KafkaProducer : IKafkaProducer
private IProducer<string, string> _producer = null;
public KafkaProducer(string brokerList,
string connectionString,
string caCertLocation)
var config = new ProducerConfig
BootstrapServers = brokerList,
SecurityProtocol = SecurityProtocol.SaslSsl,
SaslMechanism = SaslMechanism.Plain,
SaslUsername = "$ConnectionString",
SaslPassword = connectionString,
SslCaLocation = caCertLocation
_producer = new ProducerBuilder<string, string>(config).Build();
public Task SendEvent(string topicName, string key, string value)
return _producer.ProduceAsync(topicName, new Message<string, string>{
Key = key,
Value = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment