LoginSignup
2
0

More than 3 years have passed since last update.

Azure IoT Hub で Kafka Endpointが使えなかっただけの話

Posted at

タイトルの通りAzure IoT HubにKafkaクライアントからアクセスできるか確認して出来なかったという話。読む価値はないと思うけどメモ用に公開。

Event HubがKafka EndpointをサポートしたのでラッパーであるIoT Hubでも使えるだろうと予想して試してみた。結果から言うとNG。そもそもKafkaはメッセージングシステムでAzureの中ではEvent Hubが一番近いしIoT Hubのようにデバイス管理等の機能は提供しない。そのため、主に既存のKafka クライアントをターゲットとした場合Event Hubで対応するだけで十分なのかもしれない。

IoT Hub への接続確認はEvent Hubの記事を参考にした。ちなみにEvent HubにKafkaクライアントからアクセスしたらサクッとつながった。

IoT Hub 作って Event Hub-Compatible endpointにアクセス。
image.png

Azure Event Hubs for Kafka repositoryをクローンして \azure-event-hubs-for-kafka-master\quickstart\java\producer\src\main\resources\producer.configconsumer\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}";

ちなみにKafkaのTopicにあたるものはEvent Hubである。
image.png

TestProducer.javaのTopicをEvent Hub-compatible nameとおきかえる。
image.png
]

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にアクセスを試みるとTime Outが発生。

org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.

コマンドで確認してもkafkaポートは閉じていた。

Test-NetConnection -ComputerName xxxx.azure-devices.net -Port 9093

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0