【问题标题】:Connection to IBM message hub using C# and Confluent使用 C# 和 Confluent 连接到 IBM 消息中心
【发布时间】:2017-07-04 12:53:50
【问题描述】:

我正在尝试使用 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/bootstrap: 初始化 SASL 身份验证失败:SASL 机制“PLAIN”不是 平台支持

*1/1 经纪人倒闭

【问题讨论】:

    标签: c# confluent-platform message-hub


    【解决方案1】:

    我自己没有使用过 Confluent C# 客户端,但据我所知,它基于 librdkakfa,因此您至少需要更多配置才能连接到 Message Hub:

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

    【讨论】:

      【解决方案2】:

      Mickael 发布的设置是正确的。

      但是,如果您在 Windows 上运行 - 要获得 SASL/SSL 支持(Message Hub 需要),您需要 librdkafka 0.11

      使用 librdkafka 0.9.5,您无法从 Windows 连接到 MH

      【讨论】:

      • 另见这篇文章 - 了解如何设置证书路径选项stackoverflow.com/questions/44820430/…
      • 请粘贴您的日志(可能使用 debug=all),以便我们查看是连接问题还是身份验证问题
      • 日志SASL mechanism "PLAIN" not supported on platform 中的这条消息表明 librdkafka 尚未使用 SASL 支持构建。如前所述,对于 Windows,您需要在 Linux 上安装 librdkafka 0.11,您需要安装 libsasl2-dev
      • 是的,我不关注……他们呢?
      • 您使用的是哪个操作系统?获得 SASL 支持:如果 Windows - 你需要 librdkafka 0.11 如果 Linux - 你需要 libsas2-dev 如果 mac - 你需要 brew openssl 并针对其头/lib 文件进行构建
      猜你喜欢
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      • 1970-01-01
      • 2018-10-01
      • 1970-01-01
      • 2016-10-31
      相关资源
      最近更新 更多