2
votes

i'm new to azure iot hub . im trying to pull message from azure iot hub using spark streaming . im getting error when i execute the code and i could understand there is some problem in connection strings. is there any specific way to validate the connection string in spark and also please tell me the format which i specified is correct or not .

My sample code:

import org.apache.spark.eventhubs._

val eventHubName = "xyztest.azure-devices.net"
val eventHubNSConnStr = "Endpoint=sb://testname.servicebus.windows.net/;SharedAccessKeyName=primary;SharedAccessKey=abcedfgrdxyeurjrsdfyasdf="
val connStr = ConnectionStringBuilder(eventHubNSConnStr).setEventHubName(eventHubName).build 
val customEventhubParameters = EventHubsConf(connStr).setMaxEventsPerTrigger(5)
val incomingStream = spark.readStream.format("eventhubs").options(customEventhubParameters.toMap).load()
incomingStream.writeStream.outputMode("append").format("console").option("truncate", false).start().awaitTermination()

Errro:

java.util.concurrent.ExecutionException: com.microsoft.azure.eventhubs.IllegalEntityException: The messaging entity 'sb://testname.servicebus.windows.net/xyztest' could not be found.
        at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
        at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
        at org.apache.spark.eventhubs.client.EventHubsClient.partitionCount(EventHubsClient.scala:169)
1
Hi Krishnaraj, if the answer solved your issue you can accept it. If not, feel free let me know.Rita Han

1 Answers

2
votes

val eventHubName = "xyztest.azure-devices.net"

It seems you set wrong event hub name. "xyztest.azure-devices.net" should be your Azure IoT Hub hostname.

To find the event hub name you can go your iot hub-> endpoints-> events and copy the value of Event Hub-compatible name like this:

enter image description here

In the end, the event hub connect string will have the following format:

Endpoint=sb://SAMPLE;SharedAccessKeyName=KEY_NAME;SharedAccessKey=KEY;EntityPath=EVENTHUB_NAME