我试图使用IBM消息中心创建生产者和消费者应用程序。对于生产者我使用以下代码:使用C#和Confluent连接到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机制“普通纸”不 支持平台
* 1/1的经纪人下来
我恐惧它不起作用......但是,谢谢 –