0

I am trying to Post some data on a kafka topic for which the avro schema of the data contains union types.I am using kafka-rest proxy on android to produce messages.

Given that data contains union type;none of the pojo to json converters seem to work.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
arpit115
  • 38
  • 6

1 Answers1

0

Please share your the post data.

I normally do this to produce data to Kafka Avro via REST.

1) If you don't have the schema ID:

curl --request POST \
      --url http://MYKAFKARESTAPI/topics/MYTOPICNAME \
      --header 'accept: application/vnd.kafka.v2+json' \
      --header 'content-type: application/vnd.kafka.avro.v2+json' \
      --data '{
    "value_schema": "{\"type\": \"record\", \"name\": \"User\", \"fields\": [{\"name\": \"name\", \"type\": \"string\"},{\"name\": \"age\", \"type\": \"int\"}]}",
    "records": [
        {
            "value": {
                "name": "Maria",
                "age": 10
            }
        },
        {
            "value": {
                "name": "Jorge",
                "age": 11
            }
        }   
    ]
}'

If you already have the schema ID:

curl --request POST \
  --url http://MYKAFKARESTAPI/topics/MYTOPICNAME \
  --header 'accept: application/vnd.kafka.v2+json' \
  --header 'content-type: application/vnd.kafka.avro.v2+json' \
  --data '{
    "value_schema_id": 24,
    "records": [
        {
            "value": {
                "name": "Maria",
                "age": 10
            }
        },
        {
            "value": {
                "name": "Jorge",
                "age": 11
            }
        }           
    ]
}'
Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27
  • This works fine if we have to enter data manually.But my problem is I have to use fields as "name":{"string" : "maria"}.I do not have any converter for such operation.Additional problem is I have to send an array of records. – arpit115 Feb 08 '19 at 13:29