Need examples for kafka rest proxy with json

1,850 views
Skip to first unread message

Shrinivasan T

unread,
Jun 14, 2016, 10:34:24 AM6/14/16
to Confluent Platform
Hello all,

This is the example given for producing with json data.

curl -X POST -H "Content-Type: application/vnd.kafka.json.v1+json" \
      --data '{"records":[{"value":{"foo":"bar"}}]}' "http://localhost:8082/topics/logstash_logs_test"


Except this example, no other json is working.

Can anyone give few examples with more json data.

For example,

{
    "id": 1,
    "name": "A green door",
    "price": 12.50,
    "tags": ["home", "green"]
}

How to give this json data as input for kafka proxy?


Thanks.

Shrini

Ewen Cheslack-Postava

unread,
Jun 14, 2016, 2:52:00 PM6/14/16
to Confluent Platform
Hi Shrini,


Note that the structure will always have

{ "records": [
  {
    "key": <your JSON key here>,
    "value": <your JSON value here>,
    "partition": <partition number here>,
  },
  ... more records with the same format ...
]}

where key and partition are optional. So to get your single record produced, you would send:

{ "records": [
  {
    "value": {
      "id": 1,
      "name": "A green door",
      "price": 12.50,
      "tags": ["home", "green"]
    }
  }
])

-Ewen


--
You received this message because you are subscribed to the Google Groups "Confluent Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to confluent-platf...@googlegroups.com.
To post to this group, send email to confluent...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/confluent-platform/34a815a9-0dc8-4086-983a-8a84377a6a34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks,
Ewen

Shrinivasan T

unread,
Jun 14, 2016, 3:16:41 PM6/14/16
to confluent...@googlegroups.com
Thanks Ewen for the reply.

tested as


curl -X POST -H "Content-Type: application/vnd.kafka.json.v1+json" \
--data '{ "records": [{"value": {"id": 1,"name": "A green
door","price": 12.50,"tags": ["home", "green"]}}]}'
"http://localhost:8082/topics/logstash_logs_test"

It is working well.

Got reply as

{"offsets":[{"partition":0,"offset":49,"error_code":null,"error":null}],"key_schema_id":null,"value_schema_id":null}[2016-06-14
19:15:35,980] INFO 127.0.0.1 - - [14/Jun/2016:19:15:35 +0000] "POST
/topics/logstash_logs_test HTTP/1.1" 200 116 8
(io.confluent.rest-utils.requests:77)

Higor Grilo

unread,
Jan 23, 2019, 3:03:51 PM1/23/19
to Confluent Platform
Looking at this example, i come with the following question:
Lets suppose that i have two applications talking via webservice (rest), and i want to add broker in the middle (kafka), how could i convert the JSON that already is sent from the origin to kafka? 
would it be via SMT?

Thanks in advance,
Higor
Reply all
Reply to author
Forward
0 new messages