2017-07-04 31 views
0

我试图使用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的经纪人下来

回答

0

我没有用汇合C#客户本人,但据我所知它是基于librdkakfa,所以你至少需要几个月重新配置连接到集线器留言:

  • security.protocol设置为SASL_SSL
  • ssl.ca.location设为您的CA证书的路径
+0

我恐惧它不起作用......但是,谢谢 –

0

是迈克尔已经发布的设置是否正确。

然而,如果你在Windows上运行 - 让SASL/SSL支持(信息中心所需的),你需要librdkafka 0.11

随着librdkafka 0.9.5您不能从Windows连接到MH

+0

另请参阅此帖 - 了解如何设置证书路径选项 https://stackoverflow.com/questions/44820430/ibm-message-hub-communciation-with -c-sharp-confluent-api/44821846#44821846 –

+0

它仍然不起作用,我得到请求超时....但是,谢谢 –

+0

粘贴你的日志(调试=所有可能)请所以我们ca n看看它是连接还是认证问题 –