:plugin: kafka
:type: output
:default_codec: plain

///////////////////////////////////////////
START - GENERATED VARIABLES, DO NOT EDIT!
///////////////////////////////////////////
:version: %VERSION%
:release_date: %RELEASE_DATE%
:changelog_url: %CHANGELOG_URL%
:include_path: ../../../../logstash/docs/include
///////////////////////////////////////////
END - GENERATED VARIABLES, DO NOT EDIT!
///////////////////////////////////////////

[id="plugins-{type}s-{plugin}"]

=== Kafka output plugin

include::{include_path}/plugin_header.asciidoc[]

==== Description

Write events to a Kafka topic. 

This plugin uses Kafka Client 2.1.0. For broker compatibility, see the official https://cwiki.apache.org/confluence/display/KAFKA/Compatibility+Matrix[Kafka compatibility reference]. If the linked compatibility wiki is not up-to-date, please contact Kafka support/community to confirm compatibility.

If you require features not yet available in this plugin (including client version upgrades), please file an issue with details about what you need.

This output supports connecting to Kafka over:

* SSL (requires plugin version 3.0.0 or later)
* Kerberos SASL (requires plugin version 5.1.0 or later)

By default security is disabled but can be turned on as needed.

The only required configuration is the topic_id. 

The default codec is plain. Logstash will encode your events with not only the message field but also with a timestamp and hostname.

If you want the full content of your events to be sent as json, you should set the codec in the output configuration like this:
[source,ruby]
    output {
      kafka {
        codec => json
        topic_id => "mytopic"
      }
    }
    
For more information see http://kafka.apache.org/documentation.html#theproducer

Kafka producer configuration: http://kafka.apache.org/documentation.html#newproducerconfigs

[id="plugins-{type}s-{plugin}-options"]
==== Kafka Output Configuration Options

This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.

[cols="<,<,<",options="header",]
|=======================================================================
|Setting |Input type|Required
| <<plugins-{type}s-{plugin}-acks>> |<<string,string>>, one of `["0", "1", "all"]`|No
| <<plugins-{type}s-{plugin}-batch_size>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-bootstrap_servers>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-buffer_memory>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-client_id>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-compression_type>> |<<string,string>>, one of `["none", "gzip", "snappy", "lz4"]`|No
| <<plugins-{type}s-{plugin}-jaas_path>> |a valid filesystem path|No
| <<plugins-{type}s-{plugin}-kerberos_config>> |a valid filesystem path|No
| <<plugins-{type}s-{plugin}-key_serializer>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-linger_ms>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-max_request_size>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-message_key>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-metadata_fetch_timeout_ms>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-metadata_max_age_ms>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-receive_buffer_bytes>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-reconnect_backoff_ms>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-request_timeout_ms>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-retries>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-retry_backoff_ms>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-sasl_kerberos_service_name>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-sasl_mechanism>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-security_protocol>> |<<string,string>>, one of `["PLAINTEXT", "SSL", "SASL_PLAINTEXT", "SASL_SSL"]`|No
| <<plugins-{type}s-{plugin}-send_buffer_bytes>> |<<number,number>>|No
| <<plugins-{type}s-{plugin}-ssl_endpoint_identification_algorithm>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-ssl_key_password>> |<<password,password>>|No
| <<plugins-{type}s-{plugin}-ssl_keystore_location>> |a valid filesystem path|No
| <<plugins-{type}s-{plugin}-ssl_keystore_password>> |<<password,password>>|No
| <<plugins-{type}s-{plugin}-ssl_keystore_type>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-ssl_truststore_location>> |a valid filesystem path|No
| <<plugins-{type}s-{plugin}-ssl_truststore_password>> |<<password,password>>|No
| <<plugins-{type}s-{plugin}-ssl_truststore_type>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-topic_id>> |<<string,string>>|Yes
| <<plugins-{type}s-{plugin}-value_serializer>> |<<string,string>>|No
|=======================================================================

Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
output plugins.

&nbsp;

[id="plugins-{type}s-{plugin}-acks"]
===== `acks` 

  * Value can be any of: `0`, `1`, `all`
  * Default value is `"1"`

The number of acknowledgments the producer requires the leader to have received
before considering a request complete.

acks=0,   the producer will not wait for any acknowledgment from the server at all.
acks=1,   This will mean the leader will write the record to its local log but
          will respond without awaiting full acknowledgement from all followers.
acks=all, This means the leader will wait for the full set of in-sync replicas to acknowledge the record.

[id="plugins-{type}s-{plugin}-batch_size"]
===== `batch_size` 

  * Value type is <<number,number>>
  * Default value is `16384`

The producer will attempt to batch records together into fewer requests whenever multiple
records are being sent to the same partition. This helps performance on both the client
and the server. This configuration controls the default batch size in bytes.

[id="plugins-{type}s-{plugin}-bootstrap_servers"]
===== `bootstrap_servers` 

  * Value type is <<string,string>>
  * Default value is `"localhost:9092"`

This is for bootstrapping and the producer will only use it for getting metadata (topics,
partitions and replicas). The socket connections for sending the actual data will be
established based on the broker information returned in the metadata. The format is
`host1:port1,host2:port2`, and the list can be a subset of brokers or a VIP pointing to a
subset of brokers.

[id="plugins-{type}s-{plugin}-buffer_memory"]
===== `buffer_memory` 

  * Value type is <<number,number>>
  * Default value is `33554432`

The total bytes of memory the producer can use to buffer records waiting to be sent to the server.

[id="plugins-{type}s-{plugin}-client_id"]
===== `client_id` 

  * Value type is <<string,string>>
  * There is no default value for this setting.

The id string to pass to the server when making requests.
The purpose of this is to be able to track the source of requests beyond just
ip/port by allowing a logical application name to be included with the request

[id="plugins-{type}s-{plugin}-compression_type"]
===== `compression_type` 

  * Value can be any of: `none`, `gzip`, `snappy`, `lz4`
  * Default value is `"none"`

The compression type for all data generated by the producer.
The default is none (i.e. no compression). Valid values are none, gzip, or snappy.

[id="plugins-{type}s-{plugin}-jaas_path"]
===== `jaas_path` 

  * Value type is <<path,path>>
  * There is no default value for this setting.

The Java Authentication and Authorization Service (JAAS) API supplies user authentication and authorization 
services for Kafka. This setting provides the path to the JAAS file. Sample JAAS file for Kafka client:
[source,java]
----------------------------------
KafkaClient {
  com.sun.security.auth.module.Krb5LoginModule required
  useTicketCache=true
  renewTicket=true
  serviceName="kafka";
  };
----------------------------------

Please note that specifying `jaas_path` and `kerberos_config` in the config file will add these 
to the global JVM system properties. This means if you have multiple Kafka inputs, all of them would be sharing the same 
`jaas_path` and `kerberos_config`. If this is not desirable, you would have to run separate instances of Logstash on 
different JVM instances.

[id="plugins-{type}s-{plugin}-kerberos_config"]
===== `kerberos_config` 

  * Value type is <<path,path>>
  * There is no default value for this setting.

Optional path to kerberos config file. This is krb5.conf style as detailed in https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html

[id="plugins-{type}s-{plugin}-key_serializer"]
===== `key_serializer` 

  * Value type is <<string,string>>
  * Default value is `"org.apache.kafka.common.serialization.StringSerializer"`

Serializer class for the key of the message

[id="plugins-{type}s-{plugin}-linger_ms"]
===== `linger_ms` 

  * Value type is <<number,number>>
  * Default value is `0`

The producer groups together any records that arrive in between request
transmissions into a single batched request. Normally this occurs only under
load when records arrive faster than they can be sent out. However in some circumstances
the client may want to reduce the number of requests even under moderate load.
This setting accomplishes this by adding a small amount of artificial delay—that is,
rather than immediately sending out a record the producer will wait for up to the given delay
to allow other records to be sent so that the sends can be batched together.

[id="plugins-{type}s-{plugin}-max_request_size"]
===== `max_request_size` 

  * Value type is <<number,number>>
  * Default value is `1048576`

The maximum size of a request

[id="plugins-{type}s-{plugin}-message_key"]
===== `message_key` 

  * Value type is <<string,string>>
  * There is no default value for this setting.

The key for the message

[id="plugins-{type}s-{plugin}-metadata_fetch_timeout_ms"]
===== `metadata_fetch_timeout_ms` 

  * Value type is <<number,number>>
  * Default value is `60000`

the timeout setting for initial metadata request to fetch topic metadata.

[id="plugins-{type}s-{plugin}-metadata_max_age_ms"]
===== `metadata_max_age_ms` 

  * Value type is <<number,number>>
  * Default value is `300000`

the max time in milliseconds before a metadata refresh is forced.

[id="plugins-{type}s-{plugin}-receive_buffer_bytes"]
===== `receive_buffer_bytes` 

  * Value type is <<number,number>>
  * Default value is `32768`

The size of the TCP receive buffer to use when reading data

[id="plugins-{type}s-{plugin}-reconnect_backoff_ms"]
===== `reconnect_backoff_ms` 

  * Value type is <<number,number>>
  * Default value is `10`

The amount of time to wait before attempting to reconnect to a given host when a connection fails.

[id="plugins-{type}s-{plugin}-request_timeout_ms"]
===== `request_timeout_ms` 

  * Value type is <<string,string>>
  * There is no default value for this setting.

The configuration controls the maximum amount of time the client will wait
for the response of a request. If the response is not received before the timeout
elapses the client will resend the request if necessary or fail the request if
retries are exhausted.

[id="plugins-{type}s-{plugin}-retries"]
===== `retries` 

  * Value type is <<number,number>>
  * There is no default value for this setting.

The default retry behavior is to retry until successful. To prevent data loss,
the use of this setting is discouraged.

If you choose to set `retries`, a value greater than zero will cause the
client to only retry a fixed number of times. This will result in data loss
if a transport fault exists for longer than your retry count (network outage,
Kafka down, etc).

A value less than zero is a configuration error.

[id="plugins-{type}s-{plugin}-retry_backoff_ms"]
===== `retry_backoff_ms` 

  * Value type is <<number,number>>
  * Default value is `100`

The amount of time to wait before attempting to retry a failed produce request to a given topic partition.

[id="plugins-{type}s-{plugin}-sasl_kerberos_service_name"]
===== `sasl_kerberos_service_name` 

  * Value type is <<string,string>>
  * There is no default value for this setting.

The Kerberos principal name that Kafka broker runs as. 
This can be defined either in Kafka's JAAS config or in Kafka's config.

[id="plugins-{type}s-{plugin}-sasl_mechanism"]
===== `sasl_mechanism` 

  * Value type is <<string,string>>
  * Default value is `"GSSAPI"`

http://kafka.apache.org/documentation.html#security_sasl[SASL mechanism] used for client connections. 
This may be any mechanism for which a security provider is available.
GSSAPI is the default mechanism.

[id="plugins-{type}s-{plugin}-security_protocol"]
===== `security_protocol` 

  * Value can be any of: `PLAINTEXT`, `SSL`, `SASL_PLAINTEXT`, `SASL_SSL`
  * Default value is `"PLAINTEXT"`

Security protocol to use, which can be either of PLAINTEXT,SSL,SASL_PLAINTEXT,SASL_SSL

[id="plugins-{type}s-{plugin}-send_buffer_bytes"]
===== `send_buffer_bytes` 

  * Value type is <<number,number>>
  * Default value is `131072`

The size of the TCP send buffer to use when sending data.

[id="plugins-{type}s-{plugin}-ssl_endpoint_identification_algorithm"]
===== `ssl_endpoint_identification_algorithm`

  * Value type is <<string,string>>
  * Default value is `"https"`

The endpoint identification algorithm, defaults to `"https"`. Set to empty string `""` to disable

[id="plugins-{type}s-{plugin}-ssl_key_password"]
===== `ssl_key_password` 

  * Value type is <<password,password>>
  * There is no default value for this setting.

The password of the private key in the key store file.

[id="plugins-{type}s-{plugin}-ssl_keystore_location"]
===== `ssl_keystore_location` 

  * Value type is <<path,path>>
  * There is no default value for this setting.

If client authentication is required, this setting stores the keystore path.

[id="plugins-{type}s-{plugin}-ssl_keystore_password"]
===== `ssl_keystore_password` 

  * Value type is <<password,password>>
  * There is no default value for this setting.

If client authentication is required, this setting stores the keystore password

[id="plugins-{type}s-{plugin}-ssl_keystore_type"]
===== `ssl_keystore_type` 

  * Value type is <<string,string>>
  * There is no default value for this setting.

The keystore type.

[id="plugins-{type}s-{plugin}-ssl_truststore_location"]
===== `ssl_truststore_location` 

  * Value type is <<path,path>>
  * There is no default value for this setting.

The JKS truststore path to validate the Kafka broker's certificate.

[id="plugins-{type}s-{plugin}-ssl_truststore_password"]
===== `ssl_truststore_password` 

  * Value type is <<password,password>>
  * There is no default value for this setting.

The truststore password

[id="plugins-{type}s-{plugin}-ssl_truststore_type"]
===== `ssl_truststore_type` 

  * Value type is <<string,string>>
  * There is no default value for this setting.

The truststore type.

[id="plugins-{type}s-{plugin}-topic_id"]
===== `topic_id` 

  * This is a required setting.
  * Value type is <<string,string>>
  * There is no default value for this setting.

The topic to produce messages to

[id="plugins-{type}s-{plugin}-value_serializer"]
===== `value_serializer` 

  * Value type is <<string,string>>
  * Default value is `"org.apache.kafka.common.serialization.StringSerializer"`

Serializer class for the value of the message



[id="plugins-{type}s-{plugin}-common-options"]
include::{include_path}/{type}.asciidoc[]

:default_codec!:
