Skip to content

Instantly share code, notes, and snippets.

@flinox
Last active December 6, 2020 06:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flinox/1c51113b547a4373e24d81db7f9567f4 to your computer and use it in GitHub Desktop.
Save flinox/1c51113b547a4373e24d81db7f9567f4 to your computer and use it in GitHub Desktop.
Kafka: Produce message in avro format on a kafka topic through confluent REST proxy
-- PRODUCE MESSAGE AVRO
curl --request POST \
--url http://{{hostname_rest_proxy}}:8082/topics/topic-name \
--header 'accept: application/vnd.kafka.v2+json, application/vnd.kafka+json, application/json' \
--header 'content-type: application/vnd.kafka.avro.v2+json' \
--data '{
"value_schema": "{\"namespace\":\"br.com.flinox\",\"name\":\"course\",\"type\":\"record\",\"doc\":\"This schema defines a course\",\"aliases\":[\"class\",\"school\"],\"fields\":[{\"name\":\"course_source\",\"doc\":\"The system source of course\",\"type\":\"string\"},{\"name\":\"course_code\",\"doc\":\"The code of the course\",\"type\":\"int\"},{\"name\":\"course_name\",\"doc\":\"Name of the course\",\"type\":\"string\"},{\"name\":\"course_type\",\"doc\":\"Type of the course\",\"type\":\"string\"}]}",
"records": [
{
"value": {"course_source": "system_A", "course_code": 10, "course_name": "Information Systems", "course_type": "G"}
},
{
"value": {"course_source": "system_B", "course_code": 8, "course_name": "information systems...", "course_type": "P"},
"partition": 0
}
]
}
'
-- RETURN 200 - OK ( return sample )
{
"offsets": [
{
"partition": 1,
"offset": 0,
"error_code": null,
"error": null
},
{
"partition": 0,
"offset": 0,
"error_code": null,
"error": null
}
],
"key_schema_id": null,
"value_schema_id": 38
}
-- PRODUCE MESSAGE AVRO WITH ID
curl --request POST \
--url http://{{hostname_rest_proxy}}:8082/topics/topic-name \
--header 'accept: application/vnd.kafka.v2+json, application/vnd.kafka+json, application/json' \
--header 'content-type: application/vnd.kafka.avro.v2+json' \
--data '{
"value_schema_id": 38 ,
"records": [
{
"value": {"course_source": "system_A", "course_code": 10, "course_name": "INFORMATION SYSTEMS", "course_type": "G"}
},
{
"value": {"course_source": "system_B", "course_code": 8, "course_name": "INFORMATION SYSTEMS", "course_type": "P"},
"partition": 0
}
]
}
'
-- RETURN 200 - OK ( return sample )
{
"offsets": [
{
"partition": 0,
"offset": 4,
"error_code": null,
"error": null
},
{
"partition": 0,
"offset": 5,
"error_code": null,
"error": null
}
],
"key_schema_id": null,
"value_schema_id": 38
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment