All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.soento.logback.kafka.keying.ThreadNameKeyingStrategy Maven / Gradle / Ivy

There is a newer version: 1.2.10-RELEASE
Show newest version
package com.soento.logback.kafka.keying;

import ch.qos.logback.classic.spi.ILoggingEvent;

import java.nio.ByteBuffer;

/**
 * This strategy uses the calling threads name as partitioning key. This ensures that all messages logged by the
 * same thread will remain in the correct order for any consumer.
 * But this strategy can lead to uneven log distribution for a small number of thread(-names) (compared to the number of partitions).
 * @since 0.0.1
 */
public class ThreadNameKeyingStrategy implements KeyingStrategy {

    @Override
    public byte[] createKey(ILoggingEvent e) {
        return ByteBuffer.allocate(4).putInt(e.getThreadName().hashCode()).array();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy