Skip to content

Instantly share code, notes, and snippets.

@dbarkol
Created May 17, 2019 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbarkol/09bf4d9d5e4ec7e4fbb6fa271b7048a9 to your computer and use it in GitHub Desktop.
Save dbarkol/09bf4d9d5e4ec7e4fbb6fa271b7048a9 to your computer and use it in GitHub Desktop.
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