我尝试使用IBM消息中心创建生产者和消费者应用程序。对于制作人我使用以下代码:
var config = new Dictionary<string, object> {
{ "bootstrap.servers", brokerList },
{ "group.id", "simple-csharp-producer" },
{ "client.id", "some string for id such as FR45fHth..." },
{"api.version.request","true" },
{"sasl.mechanisms","PLAIN" },
{"sasl.username","the first 16 charachters of the client.id" },
{"sasl.password","the other characters left" }
};
using (var producer = new Producer<Null, string>(config, null, new StringSerializer(Encoding.UTF8)))
{
....
}
消费者使用类似的配置属性。
消费者的其余代码:
using (var consumer = new Consumer<Null, string>(config, null, new StringDeserializer(Encoding.UTF8)))
{
consumer.Assign(new List<TopicPartitionOffset> { new TopicPartitionOffset(topics, 0, 0) });
while (true)
{
Message<Null, string> msg;
if (consumer.Consume(out msg, TimeSpan.FromSeconds(1)))
{
Console.WriteLine($"Topic: {msg.Topic} Partition: {msg.Partition} Offset: {msg.Offset} {msg.Value}");
}
}
}
和制片人:
using (var producer = new Producer<Null, string>(config, null, new StringSerializer(Encoding.UTF8)))
{
Console.WriteLine($"{producer.Name} producing on {topicName}. q to exit.");
string text;
while ((text = Console.ReadLine()) != "q")
{
var deliveryReport = producer.ProduceAsync(topicName, null, text);
deliveryReport.ContinueWith(task =>
{
Console.WriteLine($"Partition: {task.Result.Partition}, Offset: {task.Result.Offset}");
});
}
// Tasks are not waited on synchronously (ContinueWith is not synchronous),
// so it's possible they may still in progress here.
producer.Flush(Convert.ToInt32(TimeSpan.FromSeconds(10)));
无论如何,它没有工作,没有任何迹象表明得到任何东西...... 缺什么? 或者我可以使用它来工作?
我得到的日志:
* sasl_ssl://kafka03-prod02.messagehub.services.eu-gb.bluemix.net:9093 /自举: 无法初始化SASL身份验证:SASL机制&#34; PLAIN&#34;不 在平台上支持
* 1/1经纪人失败
答案 0 :(得分:0)
我自己没有使用过Confluent C#客户端,但据我所知,它基于librdkakfa,因此您至少需要更多配置才能连接到Message Hub:
security.protocol
设置为SASL_SSL
ssl.ca.location
设置为CA证书的路径答案 1 :(得分:0)
Mickael发布的设置是正确的。
但是,如果您在Windows上运行 - 获得SASL / SSL支持(Message Hub需要),则需要librdkafka 0.11
使用librdkafka 0.9.5,您无法从Windows连接到MH