2017-07-04 35 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看看它是連接還是認證問題 –