仅仅是Azure IoT Hub无法使用Kafka Endpoint的问题
标题所说的是确认是否可以从Kafka客户端访问Azure IoT Hub,但结果无法实现。我认为没有阅读的价值,但为了备忘起见进行公开。
由于Event Hub支持Kafka Endpoint,所以我预测在IoT Hub这个包装器中也可以使用。但结果是不行的。首先,Kafka本身是一种消息系统,在Azure中Event Hub是最接近它的,而不像IoT Hub那样提供设备管理等功能。因此,如果主要针对现有的Kafka客户端,只用Event Hub可能已经足够了。
对于IoT Hub的连接确认,我参考了Event Hub的文章。顺便说一下,当我使用Kafka客户端访问Event Hub时,连接是很快的。

克隆 Azure Event Hubs for Kafka 存储库,并修改 \azure-event-hubs-for-kafka-master\quickstart\java\producer\src\main\resources\producer.config 和 consumer\src\main\resources\producer.config。
bootstrap.servers=NAMESPACENAME.servicebus.windows.net:9093
security.protocol=SASL_SSL
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="{YOUR.EVENTHUBS.CONNECTION.STRING}";


public class TestProducer {
//Change constant to send messages to the desired topic, for this example we use 'test'
private final static String TOPIC = "xxxx-iotoh-hub";
请前往kafka\azure-event-hubs-for-kafka-master\quickstart\java\producer并执行以下命令。
mvn clean package
mvn exec:java -Dexec.mainClass="TestProducer"
在使用Windows 10环境下的Power Shell时,出现了以下错误。切换到命令提示符后问题得到解决。
[ERROR] Unknown lifecycle phase ".mainClass=TestProducer". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
问题已经解决,但接下来出现了认证错误。虽然Kafka端口空闲,但即使给予了高权限也无法解决问题。(如果有成功的经验,请留下评论)
Finished sending 100 messages from thread #14!
org.apache.kafka.common.errors.TopicAuthorizationException: Not authorized to access topics: [upskill-iotoh-hub]
顺便提一下,当尝试访问IoT Hub的Endpoint时发生了超时。
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
使用命令确认后,发现kafka端口已关闭。
测试网络连接 – 计算机名 xxxx.azure-devices.net – 端口 9093