Class KafkaAccessLogWriter<K,V>
java.lang.Object
com.linecorp.armeria.server.logging.kafka.KafkaAccessLogWriter<K,V>
- All Implemented Interfaces:
AccessLogWriter
public final class KafkaAccessLogWriter<K,V> extends Object implements AccessLogWriter
An
AccessLogWriter
that sends access logs to a Kafka backend.
This method returns immediately after the Producer.send(ProducerRecord, Callback)
returns rather
than waiting for returned Future
completes so logs which are written and are not yet flushed can
be lost if an application crashes in unclean way.
-
Constructor Summary
Constructors Constructor Description KafkaAccessLogWriter(Producer<K,V> producer, String topic, Function<? super RequestLog,? extends K> keyExtractor, Function<? super RequestLog,? extends V> valueExtractor)
Creates a new instance.KafkaAccessLogWriter(Producer<K,V> producer, String topic, Function<? super RequestLog,? extends V> valueExtractor)
Creates a new instance. -
Method Summary
Modifier and Type Method Description void
log(RequestLog log)
Logs the specifiedRequestLog
.CompletableFuture<Void>
shutdown()
Shuts down thisAccessLogWriter
.
-
Constructor Details
-
KafkaAccessLogWriter
public KafkaAccessLogWriter(Producer<K,V> producer, String topic, Function<? super RequestLog,? extends V> valueExtractor)Creates a new instance.- Parameters:
producer
- a KafkaProducer
which is used to send logs to Kafkatopic
- the name of topic which is used to send logsvalueExtractor
- aFunction
that extracts aV
-typed record value from aRequestLog
. TheFunction
is allowed to returnnull
to skip logging for the givenRequestLog
.
-
KafkaAccessLogWriter
public KafkaAccessLogWriter(Producer<K,V> producer, String topic, Function<? super RequestLog,? extends K> keyExtractor, Function<? super RequestLog,? extends V> valueExtractor)Creates a new instance.- Parameters:
producer
- a KafkaProducer
which is used to send logs to Kafkatopic
- the name of topic which is used to send logskeyExtractor
- aFunction
that extracts aK
-typed record key from aRequestLog
. TheFunction
is allowed to returnnull
to leave the record key unspecified.valueExtractor
- aFunction
that extracts aV
-typed record value from aRequestLog
. TheFunction
is allowed to returnnull
to skip logging for the givenRequestLog
.
-
-
Method Details
-
log
Description copied from interface:AccessLogWriter
Logs the specifiedRequestLog
.- Specified by:
log
in interfaceAccessLogWriter
-
shutdown
Description copied from interface:AccessLogWriter
Shuts down thisAccessLogWriter
.- Specified by:
shutdown
in interfaceAccessLogWriter
- Returns:
- the
CompletableFuture
which is completed when thisAccessLogWriter
has been shut down.
-