1

I am new to Flume and working on sending flume events using the HTTP Source. I am able to successfully send an event if the payload is formated as bellow:

[{
"headers" : {
         "timestamp" : "434324343",
         "host" : "random_host.example.com"
         },
"body" : "random_body"
}]

However, Similar to the header I need to send the body as a JSONObject, not a string. For example:

[{
"headers" : {
         "timestamp" : "434324343",
         "host" : "random_host.example.com"
         },
"body" : {
         "value1" : "100",
         "value2" : "101"
         }
}]

How can i achive this?

Thanks in advance.

mil06
  • 29
  • 8
  • Which sink are you using? There are some of them allowing you to serialize both headers and body. Examples: http://stackoverflow.com/questions/33379438/flume-is-there-a-way-to-store-avro-event-header-body-into-hdfs and http://stackoverflow.com/questions/27834950/is-it-possible-to-write-flume-headers-to-hdfs-sink-and-drop-the-body – frb Nov 17 '15 at 14:49

1 Answers1

0

Per my konwing, we don't need to care too much about whether the JSONObject is sent or not, we an sent a Json String(can be parsed to JSONObject). You can use many tools like GSon/FastJson to transform the string to Array/Map, or the JSONObject.

Below is a example:

Gson gson = new Gson();
String body = "{\"timestamp\":\"434324343\",\"host\":\"random_host.example.com\"}";

Map map = gson.fromJson(body, new TypeToken>() {}.getType());

Tough
  • 1