title: Producing Avro type message in spark sql 2.4.4 data frame to Kafka
body: <p>I am trying to write Avro messages into Kafka in spark SQL. Can someone suggest me how to implement it in java? I found a scala reference code but not Java.</p>
  
  <p>I tried it but throwing error and where can I configure the schema registry. </p>
  
  <pre><code>aggr.selectExpr("CAST(order_id AS String) AS key", "to_avro(struct(*)) AS value").write().format("kafka").option("kafka.bootstrap.servers", "localhost:9092").option("topic", "aggr_topic").save();
  </code></pre>
  
  <p>or please replicate scala code to java .</p>
  
  <pre><code>val df = spark
    .readStream
    .format("kafka")
    .option("kafka.bootstrap.servers", kafkaURL)
    .option("subscribe", "t")
    .load()
    .select(
      from_avro($"key", "t-key", schemaRegistryURL).as("key"),
      from_avro($"value", "t-value", schemaRegistryURL).as("value"))
  </code></pre>
  
  <p>Thanks in advance.</p>