Kafka input and output plugin for Fluentd
Kafka input and output plugin for Fluentd
A fluentd plugin to both consume and produce data for Apache Kafka.
Add this line to your application's Gemfile:
gem 'fluent-plugin-kafka'And then execute:
$ bundleOr install it yourself as:
$ gem install fluent-plugin-kafka --no-documentIf you want to use zookeeper related parameters, you also need to install zookeeper gem. zookeeper gem includes native extension, so development tools are needed, e.g. ruby-devel, gcc, make and etc.
Set path to SSL related files. See Encryption and Authentication using SSL for more detail.
Set principal and path to keytab for SASL/GSSAPI authentication. See Authentication using SASL for more details.
Set username, password, scram_mechanism and sasl_over_ssl for SASL/Plain or Scram authentication. See Authentication using SASL for more details.
Consume events by single consumer.
@type kafka
brokers :,:,..
topics
format :default => json
message_key
add_prefix
add_suffix
# Optionally, you can manage topic offset by using zookeeper
offset_zookeeper :,:,..)>
offset_zk_root_node default => '/fluent-plugin-kafka'
# ruby-kafka consumer options
max_bytes (integer) :default => nil (Use default of ruby-kafka)
max_wait_time (integer) :default => nil (Use default of ruby-kafka)
min_bytes (integer) :default => nil (Use default of ruby-kafka)Supports a start of processing from the assigned offset for specific topics.
@type kafka
brokers :,:,..
format
topic
partition
offset
topic
partition
offset See also ruby-kafka README for more detailed documentation about ruby-kafka.
Consuming topic name is used for event tag. So when the target topic name is app_event, the tag is app_event. If you want to modify tag, use add_prefix or add_suffix parameters. With add_prefix kafka, the tag is kafka.app_event.
Consume events by kafka consumer group features..
@type kafka_group
brokers :,:,..
consumer_group
topics
format :default => json
message_key
kafka_message_key
add_headers
add_prefix
add_suffix
retry_emit_limit
use_record_time (Deprecated. Use 'time_source record' instead.)
time_source :default => now
time_format
# ruby-kafka consumer options
max_bytes (integer) :default => 1048576
max_wait_time (integer) :default => nil (Use default of ruby-kafka)
min_bytes (integer) :default => nil (Use default of ruby-kafka)
offset_commit_interval (integer) :default => nil (Use default of ruby-kafka)
offset_commit_threshold (integer) :default => nil (Use default of ruby-kafka)
fetcher_max_queue_size (integer) :default => nil (Use default of ruby-kafka)
refresh_topic_interval (integer) :default => nil (Use default of ruby-kafka)
start_from_beginning (bool) :default => trueSee also ruby-kafka README for more detailed documentation about ruby-kafka options.
topics supports regex pattern since v0.13.1. If you want to use regex pattern, use /pattern/ like /foo.*/.
Consuming topic name is used for event tag. So when the target topic name is app_event, the tag is app_event. If you want to modify tag, use add_prefix or add_suffix parameter. With add_prefix kafka, the tag is kafka.app_event.
:warning: The in_rdkafka_group consumer was not yet tested under heavy production load. Use it at your own risk!
With the introduction of the rdkafka-ruby based input plugin we hope to support Kafka brokers above version 2.1 where we saw compatibility issues when using the ruby-kafka based @kafka_group input type. The rdkafka-ruby lib wraps the highly performant and production ready librdkafka C lib.
@type rdkafka_group
topics
format :default => json
message_key
kafka_message_key
add_headers
add_prefix
add_suffix
retry_emit_limit
use_record_time (Deprecated. Use 'time_source record' instead.)
time_source :default => now
time_format
# The SSL and SASL parameters in "Common parameters" are mapped to librdkafka
# properties. Keys given in kafka_configs take precedence over the mapped values.
# ssl_ca_cert uses only its first entry, and ssl_client_cert_chain is not mapped.
# When true, SASL authentication requires an SSL connection
sasl_over_ssl (bool) :default => true
# kafka consumer options
max_wait_time_ms 500
max_batch_size 10000
kafka_configs {
"bootstrap.servers": "brokers :,:",
"group.id": ""
}See also rdkafka-ruby and librdkafka for more detailed documentation about Kafka consumer options.
topics supports POSIX Extended Regular Expression pattern (not Ruby regex syntax) since v0.19.6. If you want to use regex pattern, use /pattern/ like /foo.*/.
Note: A caret (^) is automatically added to the beginning of the pattern.
Consuming topic name is used for event tag. So when the target topic name is app_event, the tag is app_event. If you want to modify tag, use add_prefix or add_suffix parameter. With add_prefix kafka, the tag is kafka.app_event.
This kafka2 plugin is for fluentd v1 or later. This plugin uses ruby-kafka producer for writing data.
If ruby-kafka doesn't fit your kafka environment, check rdkafka2 plugin instead. This will be out_kafka plugin in the future.
@type kafka2
brokers :,:,.. # Set brokers directly
# Kafka topic, placerholders are supported. Chunk keys are required in the Buffer section inorder for placeholders
# to work.
topic (string) :default => nil
topic_key (string) :default => 'topic'
partition_key (string) :default => 'partition'
partition_key_key (string) :default => 'partition_key'
message_key_key (string) :default => 'message_key'
default_topic (string) :default => nil
default_partition_key (string) :default => nil
record_key (string) :default => nil
default_message_key (string) :default => nil
exclude_topic_key (bool) :default => false
exclude_partition_key (bool) :default => false
exclude_partition (bool) :default => false
exclude_message_key (bool) :default => false
get_kafka_client_log (bool) :default => false
headers (hash) :default => {}
headers_from_record (hash) :default => {}
use_event_time (bool) :default => false
use_default_for_unknown_topic (bool) :default => false
discard_kafka_delivery_failed (bool) :default => false (No discard)
partitioner_hash_function (enum) (crc32|murmur2) :default => 'crc32'
share_producer (bool) :default => false
idempotent (bool) :default => false
# If you intend to rely on AWS IAM auth to MSK with long lived credentials
# https://docs.aws.amazon.com/msk/latest/developerguide/iam-access-control.html
#
# For AWS STS support, see status in
# - https://github.com/zendesk/ruby-kafka/issues/944
# - https://github.com/zendesk/ruby-kafka/pull/951
sasl_aws_msk_iam_access_key_id (string) :default => nil
sasl_aws_msk_iam_secret_key_id (string) :default => nil
sasl_aws_msk_iam_aws_region (string) :default => nil
@type (json|ltsv|msgpack|attr:|) :default => json
# Optional. See https://docs.fluentd.org/v/1.0/configuration/inject-section
tag_key tag
time_key time
# See fluentd document for buffer related parameters: https://docs.fluentd.org/v/1.0/configuration/buffer-section
# Buffer chunk key should be same with topic_key. If value is not found in the record, default_topic is used.
flush_interval 10s
# ruby-kafka producer options
idempotent (bool) :default => false
sasl_over_ssl (bool) :default => true
max_send_retries (integer) :default => 1
required_acks (integer) :default => -1
ack_timeout (integer) :default => nil (Use default of ruby-kafka)
compression_codec (string) :default => nil (No compression. Depends on ruby-kafka: https://github.com/zendesk/ruby-kafka#compression)The in uses fluentd's formatter plugins. See formatter article.
Note: Java based Kafka client uses murmur2 as partitioner function by default. If you want to use same partitioning behavior with fluent-plugin-kafka, change it to murmur2 instead of crc32. Note that for using murmur2 hash partitioner function, you must install digest-murmurhash gem.
ruby-kafka sometimes returns Kafka::DeliveryFailed error without good information.
In this case, get_kafka_client_log is useful for identifying the error cause.
ruby-kafka's log is routed to fluentd log so you can see ruby-kafka's log in fluentd logs.
Supports following ruby-kafka's producer options.
If you want to know about detail of monitoring, see also https://github.com/zendesk/ruby-kafka#monitoring
See also Kafka::Client for more detailed documentation about ruby-kafka.
This plugin supports compression codec "snappy" also. Install snappy module before you use snappy compression.
$ gem install snappy --no-documentsnappy gem uses native extension, so you need to install several packages before. On Ubuntu, need development packages and snappy library.
$ sudo apt-get install build-essential autoconf automakeNo open issues yet, or sync has not completed.