Stream data into Azure Databricks using Event Hubs

青春壹個敷衍的年華 提交于 2019-12-24 19:29:53

问题


I want to send messages from a Twitter application to an Azure event hub. However, I am getting the an error that says instead of java.util.concurrent.ExecutorService use java.util.concurrent.ScheduledExecutorService.

I do not know how to create the EventHubClient.create now. Please help.

I am referring to code from the link

https://docs.microsoft.com/en-us/azure/azure-databricks/databricks-stream-from-eventhubs

This is error I am getting:

notebook:15: error: type mismatch; found : java.util.concurrent.ExecutorService required: java.util.concurrent.ScheduledExecutorService

val pool = `Executors.newFixedThreadPool(1)`

val eventHubClient = EventHubClient.create(connStr.toString(), pool)

Here is my code,

import java.util._
import scala.collection.JavaConverters._
import com.microsoft.azure.eventhubs._
import java.util.concurrent.{Executors, ExecutorService}

val pool: ExecutorService = Executors.newFixedThreadPool(1)
val eventHubClient = EventHubClient.create(connStr.toString(), pool)

回答1:


Create a library in your Databricks workspace using the Maven coordinates com.microsoft.azure:azure-eventhubs-spark_2.11:2.3.2 or higher version. Attach the created library to your cluster and re-attach the notebook to your cluster after it.

import java.util._
import scala.collection.JavaConverters._
import com.microsoft.azure.eventhubs._
import java.util.concurrent._
//Set up Connection to Azure Event Hubs
val namespaceName = "namespaceName_of_event_hub"
val eventHubName = "Name_of_event_hub"
val sasKeyName = "your_Sas_key_name"
val sasKey = "xxxxxxxxxxxxxxxxxxxxxxx"
val connStr = new ConnectionStringBuilder()
            .setNamespaceName(namespaceName)
            .setEventHubName(eventHubName)
            .setSasKeyName(sasKeyName)
            .setSasKey(sasKey)
val pool = Executors.newFixedThreadPool(1)
val eventHubClient = EventHubClient.create(connStr.toString(), pool)


来源:https://stackoverflow.com/questions/54693437/stream-data-into-azure-databricks-using-event-hubs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!