-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKafkaProducer.cs
43 lines (37 loc) · 1.21 KB
/
KafkaProducer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
});
}
}
}