Flume HTTP User Guide

HTTP Source

A source which accepts Flume Events by HTTP POST and GET. GET should be used for experimentation only. HTTP requests are converted into flume events by a pluggable "handler" which must implement the HTTPSourceHandler interface. This handler takes a HttpServletRequest and returns a list of flume events. All events handled from one Http request are committed to the channel in one transaction, thus allowing for increased efficiency on channels like the file channel. If the handler throws an exception, this source will return a HTTP status of 400. If the channel is full, or the source is unable to append events to the channel, the source will return a HTTP 503 - Temporarily unavailable status.

All events sent in one post request are considered to be one batch and inserted into the channel in one transaction.

This source is based on Jetty 9.4 and offers the ability to set additional Jetty-specific parameters which will be passed directly to the Jetty components.

Property Name Default Description

type

The component type name, needs to be http

port

 — 

The port the source should bind to.

bind

0.0.0.0

The hostname or IP address to listen on

handler

org.apache.flume.http.source.JSONHandler

The FQCN of the handler class.

handler.*

 — 

Config parameters for the handler

selector.type

replicating

replicating or multiplexing

selector.*

Depends on the selector.type value

interceptors

 — 

Space-separated list of interceptors

interceptors.*

ssl

false

Set the property true, to enable SSL. HTTP Source does not support SSLv3.

exclude-protocols

SSLv3

Space-separated list of SSL/TLS protocols to exclude. SSLv3 will always be excluded in addition to the protocols specified.

include-protocols

 — 

Space-separated list of SSL/TLS protocols to include. The enabled protocols will be the included protocols without the excluded protocols. If included-protocols is empty, it includes every supported protocols.

exclude-cipher-suites

 — 

Space-separated list of cipher suites to exclude.

include-cipher-suites

 — 

Space-separated list of cipher suites to include. The enabled cipher suites will be the included cipher suites without the excluded cipher suites.

keystore

Location of the keystore including keystore file name. If SSL is enabled but the keystore is not specified here, then the global keystore will be used (if defined, otherwise configuration error).

keystore-password

Keystore password. If SSL is enabled but the keystore password is not specified here, then the global keystore password will be used (if defined, otherwise configuration error).

keystore-type

JKS

Keystore type. This can be "JKS" or "PKCS12".

QueuedThreadPool.*

Jetty specific settings to be set on org.eclipse.jetty.util.thread.QueuedThreadPool. N.B. QueuedThreadPool will only be used if at least one property of this class is set.

HttpConfiguration.*

Jetty specific settings to be set on org.eclipse.jetty.server.HttpConfiguration

SslContextFactory.*

Jetty specific settings to be set on org.eclipse.jetty.util.ssl.SslContextFactory (only applicable when ssl is set to true).

ServerConnector.*

Jetty specific settings to be set on org.eclipse.jetty.server.ServerConnector

Deprecated Properties

Property Name Default Description

keystorePassword

 — 

Use keystore-password. Deprecated value will be overwritten with the new one.

excludeProtocols

SSLv3

Use exclude-protocols. Deprecated value will be overwritten with the new one.

enableSSL

false

Use ssl. Deprecated value will be overwritten with the new one.

N.B. Jetty-specific settings are set using the setter-methods on the objects listed above. For full details see the Javadoc for these classes (QueuedThreadPool, HttpConfiguration, SslContextFactory and ServerConnector).

When using Jetty-specific setings, named properites above will take precedence (for example excludeProtocols will take precedence over SslContextFactory.ExcludeProtocols). All properties will be inital lower case.

An example http source for agent named a1:

  • Properties

  • YAML

  • JSON

a1.sources = r1
a1.channels = c1
a1.sources.r1.type = http
a1.sources.r1.port = 5140
a1.sources.r1.channels = c1
a1.sources.r1.handler = org.example.rest.RestHandler
a1.sources.r1.handler.nickname = random props
a1.sources.r1.HttpConfiguration.sendServerVersion = false
a1.sources.r1.ServerConnector.idleTimeout = 300
a1:
  sources:
    r1:
      type: http
      port: 5140
      channels: c1
      handler: org.example.rest.RestHandler
      handler.nickname: random props
      HttpConfiguration:
        sendServerVersion: false
      ServerConnector:
        idleTimeout: 300
  channels: c1
"a1": {
  "sources": {
    "r1": {
      "type": "http",
      "port": 5140,
      "channels": "c1",
      "handler": "org.example.rest.RestHandler",
      "handler.nickname": "random props",
      "HttpConfiguration": {
        "sendServerVersion": false
      },
      "ServerConnector": {
        "idleTimeout": 300
      }
    }
  },
  "channels": "c1"
}

JSONHandler

A handler is provided out of the box which can handle events represented in JSON format, and supports UTF-8, UTF-16 and UTF-32 character sets. The handler accepts an array of events (even if there is only one event, the event has to be sent in an array) and converts them to a Flume event based on the encoding specified in the request. If no encoding is specified, UTF-8 is assumed. The JSON handler supports UTF-8, UTF-16 and UTF-32. Events are represented as follows.

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

To set the charset, the request must have content type specified as application/json; charset=UTF-8 (replace UTF-8 with UTF-16 or UTF-32 as required).

One way to create an event in the format expected by this handler is to use JSONEvent provided in the Flume SDK and use Google Gson to create the JSON string using the Gson#fromJson(Object, Type) method. The type token to pass as the 2nd argument of this method for list of events can be created by:

Type type = new TypeToken<List<JSONEvent>>() {}.getType();

BLOBHandler

By default HTTPSource splits JSON input into Flume events. As an alternative, BLOBHandler is a handler for HTTPSource that returns a single event, whose body is the Binary Large Object (BLOB) uploaded with the request, for example a PDF or JPG file, and whose headers are the request parameters. Note that this approach is not suitable for very large objects because it buffers up the entire BLOB in RAM.

Property Name Default Description

handler

 — 

The FQCN of this class: org.apache.flume.http.source.BLOBHandler

handler.mandatoryParameters

 — 

Comma-separated list of request parameters that must be present in every request

HTTP Sink

Behaviour of this sink is that it will take events from the channel, and send those events to a remote service using an HTTP POST request. The event content is sent as the POST body.

Error handling behaviour of this sink depends on the HTTP response returned by the target server. The sink backoff/ready status is configurable, as is the transaction commit/rollback result and whether the event contributes to the successful event drain count.

Any malformed HTTP response returned by the server where the status code is not readable will result in a backoff signal and the event is not consumed from the channel.

Required properties are in bold.

Property Name Default Description

channel

 — 

type

 — 

The component type name, needs to be http.

endpoint

 — 

The fully qualified URL endpoint to POST to

connectTimeout

5000

The socket connection timeout in milliseconds

requestTimeout

5000

The maximum request processing time in milliseconds

contentTypeHeader

text/plain

The HTTP Content-Type header

acceptHeader

text/plain

The HTTP Accept header value

defaultBackoff

true

Whether to backoff by default on receiving all HTTP status codes

defaultRollback

true

Whether to rollback by default on receiving all HTTP status codes

defaultIncrementMetrics

false

Whether to increment metrics by default on receiving all HTTP status codes

backoff.CODE

 — 

Configures a specific backoff for an individual (i.e. 200) code or a group (i.e. 2XX) code

rollback.CODE

 — 

Configures a specific rollback for an individual (i.e. 200) code or a group (i.e. 2XX) code

incrementMetrics.CODE

 — 

Configures a specific metrics increment for an individual (i.e. 200) code or a group (i.e. 2XX) code

Note that the most specific HTTP status code match is used for the backoff, rollback and incrementMetrics configuration options. If there are configuration values for both 2XX and 200 status codes, then 200 HTTP codes will use the 200 value, and all other HTTP codes in the 201-299 range will use the 2XX value.

Any empty or null events are consumed without any request being made to the HTTP endpoint.

Example for agent named a1:

  • Properties

  • YAML

  • JSON

a1.channels = c1
a1.sinks = k1
a1.sinks.k1.type = http
a1.sinks.k1.channel = c1
a1.sinks.k1.endpoint = http://localhost:8080/someuri
a1.sinks.k1.connectTimeout = 2000
a1.sinks.k1.requestTimeout = 2000
a1.sinks.k1.acceptHeader = application/json
a1.sinks.k1.contentTypeHeader = application/json
a1.sinks.k1.defaultBackoff = true
a1.sinks.k1.defaultRollback = true
a1.sinks.k1.defaultIncrementMetrics = false
a1.sinks.k1.backoff.4XX = false
a1.sinks.k1.rollback.4XX = false
a1.sinks.k1.incrementMetrics.4XX = true
a1.sinks.k1.backoff.200 = false
a1.sinks.k1.rollback.200 = false
a1.sinks.k1.incrementMetrics.200 = true
a1:
  channels: c1
  sinks:
    k1:
      type: http
      channel: c1
      endpoint: http://localhost:8080/someuri
      connectTimeout: 2000
      requestTimeout: 2000
      acceptHeader: application/json
      contentTypeHeader: application/json
      defaultBackoff: true
      defaultRollback: true
      defaultIncrementMetrics: false
      backoff:
        '4XX': false
        '200': false
      rollback:
        '4XX': false
        '200': false
      incrementMetrics:
        '4XX': true
        '200': true
"a1": {
  "channels": "c1",
  "sinks": {
    "k1": {
      "type": "http",
      "channel": "c1",
      "endpoint": "http://localhost:8080/someuri",
      "connectTimeout": 2000,
      "requestTimeout": 2000,
      "acceptHeader": "application/json",
      "contentTypeHeader": "application/json",
      "defaultBackoff": true,
      "defaultRollback": true,
      "defaultIncrementMetrics": false,
      "backoff": {
        "4XX": false,
        "200": false
      },
      "rollback": {
        "4XX": false,
        "200": false
      },
      "incrementMetrics": {
        "4XX": true,
        "200": true
      }
    }
  }
}